Priority is the order in which units display in the control group at the bottom, the display order of hero icons on the top left is based on their creation on the map; first will always be top icon, second is second icon, etc.
Also preplaced heroes take precedence over game cache restored heroes, and replacing e.g. the 1st hero by another unit via trigger will shift the order of the icons