There are two obvious reasons. I'll refer to the US specifically, but I would imagine other countries are fairly similar.
First, the historic. Before modern transport & communications, the election process could take weeks or months. California became a US state in 1850, when it could take more than four weeks to travel from there to Washington (or before the Pony Express & telegraph, even send a message). https://www.aei.org/carpe-diem/maps-of-the-day-travel-times-from-nyc-in-1800-1830-1857-and-1930/ Allowing some preparation time, newly elected Senators & Representatives couldn't realistically get to Washington before January following the election. (Indeed, until the 1930s, the new administration didn't take office until March.)
The second reason is that it takes time to organize a transition. Among other things, a new administration has to find & vet people to take cabinet posts* and other appointed offices, hire staff, and physically move. (It has taken me a month or more to do a move after buying a new house in the same town.) Newly-elected Senators & Representatives face similar problems: moving to Washington, finding housing, hiring staff, &c.
*The British & others seem to handle this by the opposition parties having "shadow cabinets" already in place when they're not in power: https://en.wikipedia.org/wiki/Shadow_Cabinet
PS: Further to your suggestion that the gap would potentially create a dangerous situation, at least in the US it's historically been the case that outgoing & incoming administrations would work together. (The current situation, with the incumbent openly suggesting that he won't accept the results of the election if he loses, is pretty well unprecedented.) Throwing a new government into the middle of a crisis would seem even more dangerous.