Because people massively underestimated the seriousness of the situation, and stayed where they were, not wanting to cut their trips short, until it was too late. Now, so many countries have travel restrictions / outright bans and the majority of flight and ferry routes are being shut down, it's almost impossible to find a way home.
I can give you this country as an example!
I help run a Facebook group for New Zealand backpackers/travellers, we have over 84,000 members so it's quite a large community. A few weeks ago, seeing what was happening in other countries, and having a first handful of cases appear in Auckland, we began advising everyone to consider returning to their home countries if they only had visitor (as opposed to work) visas and/or didn't have the funds to support themselves in the event the virus took off here and they were forced to isolate and/or lost their jobs. But people refused to listen, because we only had those few cases and the country as a whole had such a casual attitude towards it. They kept saying they'd rather stay here because it was "safe"... as if it was possible for a country visited by 3.8 million international tourists a year to escape a global pandemic

As cases increased we continued to push the advice, and although some members used their brains and started to get the message, for the most part people continued to ignore it, and tell anyone who was concerned about it that they were overreacting.
When Jacinda announced on March 14th that everyone arriving in NZ would have to self-isolate for 14 days, people were either isolating and complaining about it, or refusing to do it because they didn't think it was necessary and they didn't want to "lose" two weeks of their holiday. It seemed it was only when she closed the border to all non-citizens that it finally started to sink in. By the time people started looking for flights home, the majority of flight routes between NZ and the rest of the world were already restricted or cancelled.
Then Monday lunchtime came and Jacinda announced the country would go into lockdown in 48 hours , and all of a sudden people realised that they were up shit creek without a paddle. As of midnight tonight (it's 11.40pm as I write this) you are meant to stay where you are for the next 4 weeks, only leaving home if you are providing an essential service or need to travel to use one. Over the last couple of days we've had literally hundreds of backpackers posting and messaging because they don't have a place to stay during lockdown. Campsites are closed and freedom camping has been banned. About half the country's holiday parks are staying open, but closing their communal facilities, meaning only people in proper motorhomes and fully self-contained vans can stay there. The thousands of travellers who stay in non self-contained vehicles,or don't have vehicles at all, have had to find Air b&Bs / rooms to rent etc as most of the hostels are closed as well. Lots don't have jobs here, or enough money to support themselves.
People had plenty of warning that the situation was going to get more serious here and that they should go home, but they ignored it and stayed, and that's why they are stuck, because they didn't bloody listen.