I just had an interview like that last week where everything went perfect yet they didn’t want to hire me.
My experience in interviews (on both sides of the table) have been that often there are multiple candidates who seem like they could do the job well from a technical perspective, so the job goes to the one who the interviewer would like to work with from a personality perspective.
I’d say don’t get discouraged. When I have interviewed in the past it often took multiple good interviews before I got an offer.
I’ve been on both sides of this. Sometimes there is another candidate that is more qualified or a “better fit”. Sometimes there is an internal reason why no one gets hired at that time.
When I worked at the state we were forced to interview people even though we already knew who we were going to hire, so we just had to go through the process. Not saying this is what happened to you, just that there are a ton of reasons why you may not have got the job and they might not be honest with you as to why you didn’t get it because they don’t want to admit the truth, which had nothing to do with you personally.