I've had immigration officials checking passports at the plane door a few times. I assume that when they carry out these checks, they are looking for a particular person that is supposed to be on the flight. I've had this once on TK, IST-HEL (I've flown the route countless times). Once on AY, HEL-TLL! Once on CM flying PTY-MIA, and this time I was actually the guy they were looking for

"We got him", and off we went (and they stopped checking other passports at that time. They finally told me they had profiled me as a drug smuggler based on my itinerary. It was not a nice experience, but after thorough checks and questioning, I was let go.