Depends on the beach, if it’s illegal or not. Swimming places, definitely not.
As for why do it? Off road driving is fun, your car can provide electrical power for things like speakers, lights, and stuff, carry firewood, coolers (full of food. And booze,); sand toys, chairs, towels… elderly family that can’t walk, clamming or fishing gear; kites or surfboards or whatever else…. and to get out to a place away from crowds.
At the places people go swimming, it’s generally not allowed, sure, and same for private beaches. But there’s plenty of public beachfront that isn’t your sandy swimming spot