What you're facing is one of the hardest problems to tackle as a DM, and probably one of the harder lessons that any teacher must face in their career. That problem being the balance between shielding them from failure and letting them learn from their mistakes.
On the one hand, you want your players to have fun, and you want to create an interesting storyline where not every encounter ends by the sword.
On the other hand, you want your players' choices to matter. If that means that they miss out on a cool questline due to their murderous actions, so be it.
The difficult part is finding a balance between the two. Here's what I've found works best.
Earlier in the campaign, show them the tools they can use.
One of the bigger problems I've seen players face is that they tend to grow complacent when they find a strategy that works. If they win every encounter by fighting, then they'll see little reason to try any alternatives--and the same goes for other strategies. They charm their way past guards a few times in a row and suddenly they're rolling Persuasion on every NPC they encounter, regardless if it feels appropriate to the situation.
Once they fall into a rhythm it can be exceedingly difficult to break them out of it, so from my experience it's best to keep them off-balance early in a campaign so that they learn to assess a situation before launching into a particular stratagem. Let them lose some fights against guards or ruffians; perhaps they get robbed of their belongings or they get thrown in jail. At the same time, reward them when they use roleplaying and wordplay to their advantage, but make sure they fail when they try something that would never work, regardless of their roll.
Failure early-on into a campaign is the best way to show the players that their choices matter. And more often that not, it'll lead into interesting developments that'll feel more organic and immersive than anything you could have planned on your own.
But what do I do if they keep failing?
If your players are struggling to break into new strategies, you can tell them their options. New RPG players are often simply unaware of their options, so it's important that you make them aware of the full breadth of their abilities. This can be useful even with more experienced players stuck in the rut of habit or simply unused to the class or system they're playing.
Stating the available options can sometimes feel like you're "railroading" your players, but from my experience, the brief awkwardness is greatly outweighed by the benefits it reaps.
Then let them decide later on what tools they want to use.
Sometimes it's best to let the players keep doing what they're doing, as long as everyone is having fun. If that's not the case, as the campaign progresses, it becomes more difficult to break players out of their habits, so the options available to you generally become more extreme.
Making the players learn by their mistakes can still be useful, but at later points in the campaign you risk causing a lot of dissonance between yourself and the players if their tried-and-true methods suddenly become ineffective (e.g. "are you trying to kill the party?", "did the rules change?", "I feel like I'm being targeted").
That's why, at this point, your best option is almost always going to be a face-to-face conversation with the players. It's fully within your rights to tell them that you feel their strategies are getting stale. If you tell them that they have a chance of failure, they'll probably start being more careful with their choices, and they'll be better prepared for failure in case it happens.