They are supposed to have evolved as a group to avoid competing with the other large group of flying vertebrates: birds, which largely dominate the diurnal (daytime) skies; bats are mostly nocturnal except for flying foxes which are large tropical fruit-eating bats.
Being nocturnal, the smaller species also avoid being hunted by birds of prey such as eagles and hawks.
But it is also and perhaps mainly because of their anatomy that they have to rest on their heads. They could not take off like birds, flapping their wings from the ground (yes they can but they do not usually do it that way because it is a tremendous expenditure of energy and very uncomfortable, and their wings are not as strong as those of birds) nor gaining speed in short races because their legs are not configured as in other mammals. Bats prefer high places to perch and rest because that way they only drop down to fly. Species such as the New Zealand Shorttail are exceptions as they live and hunt close to the ground all the time.
Bats’ hind legs are turned from their hips in a 90-degree rotation and when their knees are bent they point backwards or to the sides. Many insectivorous bats hunt by forming a web-like trap with their legs and the membrane of skin between them and their tail.
Horseshoe bats hang from one leg and spin around to see what is going on around them.
A bat hanging or sleeping upside down with its legs (claws) makes no effort to hold on, its muscles are relaxed in this position (if we hang with our fingers, we have to force ourselves after a while we start to feel muscle cramps and we have to let go) .
They do not have opposable thumbs, also to minimize the effort of contracting them, their fingers are all the same length, some tendons are what close and keep the claws in place (the same mechanism of birds when they sleep clinging to a branch) and it is a mechanism so efficient that the bat must make an effort to extricate itself if it needs to fly elsewhere such as looking for food. Researchers who catch bats in their nets must also release them by pulling up first because if they are pulled down the legs automatically close.
Sometimes dead bats hang like this and you have to yank them out of their grip.
And as for why they don’t get blood rushing to their heads or get dizzy and faint on their heads, it’s because they’re adapted to being in this position unlike us (just like South American sloths and some types of Asian parrots called bat parrots that sleep upside down) their size is a factor in their favor we are too big and massive with too much blood in our torrent, all that amount increases the pressure and makes us dizzy. In a bat, gravity does not affect this fluid in the same way and it does not harm them to hang.