This is a very straightforward way to give someone advice. You use this phrase when you definitely know more about something than the people who are listening:
A: I've never eaten that before. Do you eat it raw?
B: No, you have to cook it.
You can also use "You have to ___" when you're excited about something and you want to share it:
You have to try this! It's delicious!
If you use "You have to ___" to share an opinion, you might come across as rude. For example, don't use this phrase when giving friends advice about their relationships, job, etc.