Yes, it is legal to use a VPN to play at PokerStars if online poker is allowed in your country. However, keep in mind that VPN usage doesn't make an illegal activity into a legal one. So, if you live in a region where gambling is extremely frowned upon, you might still get into trouble.
Pokerstars uses various methods to detect and block VPN usage by players. These methods include: Blacklisting known VPN IP addresses: Pokerstars maintains a list of IP addresses associated with VPN servers. If a player attempts to connect to the website using one of these IP addresses, they will be blocked.