Several things to consider.
Trudeau has some real staying power. It has been a disastrous year and a half for him. The India trip, pipeline problems and Western alienation, blackface, SNC-Lavalin, etc. And yet despite all of that, he managed to hold on. Partially this is due to the competition: Singh is cool but doesn't know how to lead a country, while Scheer is essentially unlikable and had no real platform. But Trudeau nonetheless managed to stem the bleeding and come within 13 seats of a majority by campaigning smartly - he knew his personal brand was ruined, so he focused on building infrastructure in the exact right areas.
The specific party fault-lines and regional differences played a big role in this election:
1. Quebec will mostly not vote for a party whose leader wears a turban, and would not be able to speak in their Parliament because of it.
2. NDP ruled out working with a CPC minority.
3. Bloc ruled out supporting any government in any formal way.
4. Ontario despises Doug Ford, and so the CPC hid him away - a terrible decision considering how potent the Ford brand is in certain areas of Toronto, where the CPC lost hard. Sure, he is a disaster, but he is your disaster, and he gets the stupid people out to vote.
5. Western alienation solidified the CPC vote in that area, but the reality is that everybody is sick of Alberta's shit, and its caused a giant rift between Alberta/Saskatchewan and the rest of the country. The point is that Scheer was forced to adopt significant policies that are deeply unpopular basically everywhere but those two provinces. Specifically, pipelines. Quebec is adamantly opposed to pipelines - which means the CPC lost seats in Quebec as well.
All of this pointed to a minority government for somebody, but I would argue there was never an instance where the CPC could get a minority government. Nobody wants to work with them because they don't take climate seriously, and they have to constantly pander to a high-paid portion of the country that is completely reliant on commodities, that are in turn completely dependent on a massive international market beyond our ability to control or influence.
All-in-all, the outcome of this election has seriously increased tensions across the country. I do not see it lasting long. My original prediction was 6-9 months until we see another election, but after reviewing NDP finances, I think it could be as long as 18 months.