That actually happened. The ceremony wasn’t as elaborate as portrayed in the movie though. But Stallworth did serve as David Duke’s bodyguard while he was visiting. This is about how he met Duke from HistoryvsHollywood:
Yes, but the encounter wasn't part of Stallworth's undercover work. The BlacKkKlansman true story supports what's seen in the movie. Stallworth's chief assigned him to protect David Duke during Duke's January 10, 1979 visit to Colorado Springs. "That's fine," said Duke after Stallworth introduced himself. "I appreciate the police department's efforts. Thank you." Stallworth joined Duke and his fellow Klan members at a local steakhouse for lunch. Unlike the movie, it was a regular restaurant and Duke's visit wasn't part of any ceremony. Stallworth's partner on the undercover case, portrayed by Adam Driver in the movie, was posing as the "white" Stallworth at the time and was present at the lunch. During the meal, Stallworth, who had brought a Polaroid camera, asked Duke for a favor.
"Mr. Duke, no one will ever believe me if I tell them I was your bodyguard. Would you mind taking a picture with me?" Duke agreed and Stallworth's partner, who was working undercover, took the picture. Stallworth, who stood between Duke and another Klansman, the Grand Dragon of Colorado, placed his arms around their shoulders at the last minute, just before his partner snapped the picture. Duke lunged for the picture but Stallworth was "a split second faster" and got to the photo first. Duke reached toward Stallworth but Stallworth warned him, "If you touch me, I’ll arrest you for assault on a police officer. That’s worth about five years in prison. DON’T DO IT!" Duke, furious, stepped back. Unfortunately, the photo has since been lost. -NYPost.com
If it really happened... my guess is that the assignment was intended to be a FU of sorts to both the Klan and Stallworth.
Of course most white people despise the KKK, and if the chief wanted to send a messag ees to them that the police of Colorado Springs were not on their side, that'd work. As for Stallworth, maybe it was intended to be part of his assignment, but more likely it was supposed to be a test, to see how much shit this new guy could put up with.