VPNs are legal in the vast majority of jurisdictions around the world and are widely used by individuals and companies to protect their data, including in countries with highly restrictive governments. Even where VPNs might be seen as discouraged, many governments tacitly endorse their use by officials, academics, or businesses to stay competitive in an interconnected world. It is simply not practical for countries to ban all VPNs.
Of course, illegal online activity is always illegal, whether you are using a VPN or not.