They're speed bumps.
Essentially, the only function of non-boss encounters in RPGs is to drain the party's resources, forcing some kind of balance between resource consumption in the form of items, magic points, potions, or whatever and saving those resources for the next boss fight.
Waaaaay back on the NES, there wasn't really enough memory to represent encounters on the overworld or dungeon maps, so a simpler method of determining when they were fought was used (usually randomly generating a number and decrementing it with each step the player takes, with an encounter when it reaches 0), and it's stayed as a legacy gameplay tumour ever since.
Essentially, the only function of non-boss encounters in RPGs is to drain the party's resources, forcing some kind of balance between resource consumption in the form of items, magic points, potions, or whatever and saving those resources for the next boss fight.
Waaaaay back on the NES, there wasn't really enough memory to represent encounters on the overworld or dungeon maps, so a simpler method of determining when they were fought was used (usually randomly generating a number and decrementing it with each step the player takes, with an encounter when it reaches 0), and it's stayed as a legacy gameplay tumour ever since.