Yes. Yes you can ask for feedback after a rejection.
While I don’t recommend you do this indiscriminately to all jobs to which you applied, if you were invited to a campus visit, then yes, it is in my opinion appropriate to respond to a rejection with a very brief and unemotional email to either the Department Head or the Search Committee Chair something along these lines:
I want to thank you again for hosting me at your department. I understand the position was offered to another candidate. I am writing now to inquire if you have any feedback that I might take from the visit to improve my candidacy as I move ahead in my job search. I would be most appreciative of your honest constructive critique if you see elements of my candidacy that could be improved.
Thank you for your time,
Now, to be truthful, I suspect that the norm here is that you will not get a response. I think that faculty members may well feel awkward, embarrassed, ashamed, annoyed, or just plain too busy to respond to this honest request for help.
In addition, the issues may well have little to do with the candidate personally, and more to do with “fit.” But sometimes there really is feedback that can be offered, without damaging the integrity of the search, which a candidate can take away and learn from. “Your job talk was poorly organized and needs work”; “You seemed unprepared to answer questions about basic courses that you’d teach”; “You’ll want to get better at showing an interest in the job itself and the people with whom you’re talking”; etc.
If I had *ever* been asked for this kind of feedback from an unsuccessful job candidate, I would most definitely have responded. Indeed, I longed to be able to offer feedback to many of the particularly clueless job candidates who lurched through our doors. But it is a thing that cannot be offered gratuitously.
The important thing here is not to sound needy or resentful or emotional in any way. You cannot express disappointment and resentment or personalize the rejection (“I really don’t see where I could have gone wrong”; “I don’t understand why the other candidate was better qualified than me”; etc.). A firm neutrality that you may be far from actually feeling is the key to an effective approach here.
I will reiterate that sometimes the answer is “You were great; in the end our decision revolved around the best fit for the department.” That may seem unhelpful, but it does require you to ask yourself if you really did, in reality, express your potential fit as well as you could have. Be your own harshest critic in these things. Take the step to find out who did get the job, and think about their profile and whether it has strengths that yours lacks. And take steps to fill any gaps.
The job search process is, for most, about learning from rejections. As painful as it is, assume that there is something concrete to learn from every rejection and make every job application that you send out better and more focused than the one that preceded it.