I had a customs agent ask me what country I was a citizen of after looking at my passport once, and then subsequently explain that he did so for the sake of "comparing my spoken declaration to my written declaration".
I figure this sort of apparently stupid question is designed to trip up someone who is being dishonest. Someone who hands customs a falsified US passport might slip up or become visibly nervous if they are then subsequently asked their citizenship, whereas a US citizen when asked such a question presumably can answer it without issue.
I don't get asked many questions by US immigration officials because they sort of lose interest when they realize that they are going to have to write questions down if they don't want there to be any misunderstandings. But a young and keen officer at (I think) O'Hare asked me, writing the question down, how long I had been out of the country. At Oroville, Washington (BC 97/US 97 shared-shed border crossing), the US official pointed at the Turkish visa stamp in my passport but didn't ask any questions about it when he realized he would have to write them down.
That, and it's a question to ask purely for the sake of asking a question, because the more questions you ask the tougher you look. Security theater and whatnot.
There has to be a presumption that they are videotaping everything because there is no expectation of privacy (and therefore no Fourth Amendment violation) when going through passport control, notwithstanding the routine prohibition on arriving passengers videotaping their own or others' interactions with immigration inspectors. Besides the possible reasons you cite, I have long suspected these apparently stupid questions are designed to evoke accented speech that is not consistent with the documentation presented.
Aside from the border, where the Fourth Amendment carve-out for border search has to be taken into account, I don't show a lot of patience with these seemingly obvious questions, because I find they tend to be (1) hostile attempts at elicitation or (2) opportunities for transcription error. A couple of examples:
* In the past few years, Kansas has enacted controversial voter photo ID and voter citizenship proof laws. Their stated rationale is to prevent non-citizens from voting but many, myself included, believe the actual purpose is voter suppression. Until quite recently, the elections office in my county had a practice of requiring prospective voters to recite their names before signing the poll book, in addition to showing photo ID. I have not been able to find a law or rule that gives them the authority to require this. I suspect the motivation is to elicit accented speech that can be cited as proof that the existing laws are not sufficient to keep non-citizens from voting, and thereby be used to promote even more restrictive laws for the real purpose of voter suppression. Rather than attempt to vocalize my name when asked to do so, I have said things like, "As shown in the documents presented" (invariably both my driver's license and US passport, because if they try to argue I am not really a citizen, I want to be able to come down on them like a ton of bricks); "It is actually your responsibility to say the voter's name" (I checked the statutes and yes, it is theirs); etc.
* My local public library has a Friends of the Library membership program that includes free hold requests. As a convenience, the annual renewal form gives you the opportunity to sign up for email notifications (which you can get even if you are not a Friend of the Library) and asks for your email address, but does not give you a blank to say that you are
already receiving notifications. I don't want to leave this part of the form blank, and have notifications turned off. But I also don't want to write down my email address, take a chance on the person processing the form not being able to read my handwriting, and have the correct address in their system overwritten by an incorrect one. So, on that particular blank, I write "(Already in the system)" instead of the actual email address, and write "I already receive notifications" elsewhere on the form and pray for common sense at the receiving end.