In the games I run, random encounters serve two important game functions:
1) They eat resources, thereby bringing the party closer to death. This also gives the players a chance to feel smart, by minimizing their resource expenditure, with the knowledge that spending too much now may mean the difference between life and death later on.
2) They give experience, thereby bringing the party closer to the next level. This gives the players positive feedback, making sure that they are always improving, even if they can't figure out a particular puzzle or aren't sure what they want to do next. No matter what else happens, even if you never find that magical sword you were looking for, you're still getting something out of all this.
Having played in games where resource-management wasn't a thing (because you could full-heal overnight, and were unlikely to face more than two encounters in a day), and where experience wasn't a thing (because the DM was running from a book, and giving levels at designated chapter breaks or however those work), random encounters felt like a big waste of time. They didn't consume any meaningful resources, and they didn't give experience or useful loot, so the only interesting outcome - the only outcome that changed the status quo in any way - was the miniscule chance that the party could die. It was the worst.