If you use the gerund, you’re usually referring to a habit. I like going to the beach but I prefer going to the park.
If you say ‘I prefer to go the park’ it can sound more like a one-off action (though not always). Would you like to go to beach now? Hmmm tbh I prefer to go to the park.