1- First of all, we have to see what the word اولياء means. Many scholars have noted that it doesn’t just mean “friends.” It means guardians, protectors, or very close confidants. Muslims are prohibited from giving non-Muslims the upper hand, from submitting to them, and taking them as guardians who make decisions for them. Yes, in times of Taqiyyah, they can pretend to be very close to their enemies so they don’t kill them.
2- We have to understand the socio-political circumstances of these verses. At the time, Muslims had many enemies who wanted to uproot Islam. Sometimes those enemies would pretend to be the friends of Muslims, fool and deceive them with their sweet words, and once they would earn the trust of Muslims they’d make a surprise attack, undermine them, or conspire against them. The Qur’an prohibited Muslims from falling to such deception. But if this is not the case, then it’s ok yo have a non-Muslim friend.
3- If having a non-Muslim friend (who is very close, like a best friend) puts one’s faith at risk (the non-Muslim friend influences you such that your faith is weakened), then it would be haram to have such a friend. But this also applies to Muslim friends as well. Having a corrupt Muslim friend who will weaken your faith is haram.