Teacher takes pictures of students during exams and posts them on social media

Doing this without permission is unprofessional, and it may be illegal, depending on your jurisdiction.

Asking for students' permission first is still unprofessional, especially in an exam situation, where students are already nervous, and given the power imbalance between the professor and the students. Who among the students will dare to object right before the exam? (This could depend on your local culture.)

You write that "There is no foul play involved, just for fun." - What is fun for one student could very well be harrassment for another, especially if pictures are edited. I don't see how this furthers the academic enterprise, so I would avoid doing this, at the risk of coming across as a spoilsport.

I surmise this question could soon be closed as opinion-based.

Is this behavior alright? Should it be tolerated?

Well, it certainly does not seem very professional to me, and I would neither do it nor suggest it to any other lecturer. That being said, I can certainly imagine small, informal master-level classes, where doing this may be perceived as a fun gimmick and not as outrageous.

Whether you should tolerate it probably depends on whether you are personally offended, and to what degree. If you personally don't care (and don't know somebody else who clearly cares), I do not see a reason to make a big preemptive fuss. If you would really rather not have your picture taken, or you expect the shy guy at the back to be really bothered by that, then you can (and should) talk to the lecturer in private and explain the situation to her/him.

I would bet that this is surely a FERPA violation in the U. S.

This is not based on my detailed knowledge of the law, but only my past experiences (and vague recollections from the FERPA quiz my university has everyone take).

Here's an example of how strict these laws can be: once I got an email from the parent of an autistic student in my course. The parent wanted to know how the student was doing in class so the parent could help her child stay on top of things. On a hunch, I contacted the disability services office to see if I could speak with the parent about the student in this case. I was told that it would be a violation of FERPA to even confirm with the parent that this student was enrolled in my course!

Since posting a photo of someone taking an exam is certainly evidence that they are taking a particular course, it is very likely posting the photo is not okay.