Dismounting a saddled horse instructs it to wait for you. 


When you dismount a horse that has a saddle, it remembers what happened and its position, so it will wait until you come back.


Once you ride it again, it stops waiting and acts normally.



Also you can remove its saddle anytime and it will stop waiting if you want to let it wander free again



If you want to make your horse even smarter, also check out how you can use ender pearls and bring your mount along for the ride with https://www.curseforge.com/minecraft/mc-mods/mounted-pearl-bring-your-mount-along-when-you