It's a trophy-producing stunt
People who perform daring feats often try to secure a trophy while doing it -- as proof of the deed, as a souvenir, and, because obtaining the trophy usually presents an additional challenge, as a performative flourish. It's a very natural expression of confidence and triumph.
Ron and Flip have successfully hoodwinkedha! all these KKK derps, all the way from the rank-and-file (who try to promote "Ron" to lead their local cell!) up to the national leader, David Duke. And, in doing so, they have disproved a lot of the KKK's thinking: Ron's scheme has succeeded in large part because he and Flip have excellence of character that racists believe is the exclusive domain of white men, and not of blacks or Jews.
There's an iconic scene that crystallizes a lot of this, in which Ron floats the hypothetical of his very real scheme past David Duke on the phone, and Duke discounts it out of hand:
at 1h17m55s
Ron: Aren't you ever concerned with some smart-alec n**** pretending to be white?
David: (scoffs) No. I can always tell when I'm talking to a negro.
R: How so?
D: Take you for example, Ron.
R: ...me?
D: Yeah. I mean, I can tell that you're a pure, aryan white man from the way you pronounce certain words.
...
R: ... If you had not brought it to my attention, I would not have noticed the difference between how we talk and negroes talk.
So, when events force Ron to meet Duke and the rest of the KKK cell in-person as his official police escort, using his true identity, and Ron has to rely entirely on the strength of the spycraft he and Flip have practiced up to that point, and it's working, he can't help himself: he has to spike the football.
Ron chose to pose for a photograph with the Grand Dragon of the Ku Klux Klan in an inappropriately familiar way, not because it was easy, but because it was hard, because punking the KKK served to organize and measure the best of his energies and skills, because that challenge was one that he was willing to accept, one he was unwilling to postpone, and one he intended to win.
(To paraphrase JFK.)
I had forgotten this, but it turns out that Flip is the cameraman! Ron asks Duke to pose with him, and when Duke grudgingly acquiesces, he calls Flip over to take the picture.
Flip is understandably not thrilled with Ron's prank, but he handles this wrinkle deftly, even being performatively racist by avoiding physical contact with the black man when he hands him the camera.
It's great because this stunt gives both of our heroes a chance to show off: Ron walks dangerously close to the line of being unmasked and even flexes his police power, and Flip gets a chance to show off what a stone-cold professional he is.