Now my question is that in my country, crypto is not legalized, so in case if anyone is scammed through P2P, we can't take up this matter in the legal court because the country does not recognize the transactions of crypto in the first place.
I think this is exactly the reason on why government prohibits the utilization of BTC in their jurisdiction. Since no laws have been created by their respective Congress in dealing with anything related with cryptocurrencies, this follows that if you want to venture in this practice, then you accept the risks that are associated with it.
Does this gives a free hand to scammers as they know that they cannot be punished by a court of law

I think that is a double-edged sword depending on the person they run into.
The difficult thing with cryptocurrencies is knowing which area has jurisdiction over the case in the event of a scam. If you deal with someone via p2p and they have scammed you, depending on where you are staying, then such is enforceable against them. In contrast, if they have dealt with someone who prohibits the utilization of cryptocurrencies, then they cannot enforce such action against them.