There are digressions across the laws on the use of VPN - both paid-for and free - in differing territories, especially in countries like China. However, for the most part, the use of a VPN is not illegal. Offering its users an extra layer of security, as well as optimizing the performance of elements like bandwidth, a VPN is completely legal to use.
That being said, this shouldn't be taken as a shield against any illegal activity they could potentially be used for. If you happen to be using a VPN for piracy, for example, you're still committing an illegal act and risk prosecution.
What's more, while many paid-for VPN services promote a no-logging policy, that isn't to say your information isn't completely safe from scrutiny. If the likes of the government or FBI want to take a look at what you've been up to, many VPN providers will be obligated to pass this information over. It's also worth repeating that this kind of anonymity rarely stretches to free VPN services, with your information likely to be the currency used to keep the VPN going.