A few colleagues have had this experience. They get a call about a job. It looks like a great fit. They apply. They go through all the interviewing. It takes forever. And, they don't get the job.
One asked, “Is it ok to ask why?” Sure, it's ok to ask. Just don't have a fight about it.
When you ask why you didn't get a job, it's a form of feedback. And, the people providing feedback may not be very nice about how they provide feedback. They may not be nice about it. If you are lucky enough to get this feedback, say, “Thank you.”
No matter how these people phrase it (one hiring manager said, “I don't trust you to not look for a job once the economy improves), they are providing you valuable feedback. The colleague who heard this was astonished. “I wanted that job. I wasn't going to look for a new one.” We discussed ways he might be able to use this experience to preempt a future hiring manager from thinking this way.
Something about your interviewing situation has created the rejection (maybe not you). Take the feedback, learn from it, and think about ways to apply it. Say, “Thank you,” and stop. Do not fight with the person giving you feedback. Who knows, that person might think of you in a while and re-open discussions. Stranger things have happened.