The leader of the party that forms the government automatically becomes PM, even if they doesn’t have a seat in parliament.
Funny enough, the last time it happened was in 1984, when Trudeau Sr. resigned and John Turner, who was not a sitting MP, won the Liberal leadership contest. During his time in PM, he had to attend parliament sitting in the visitor’s gallery.
And as is the case any time someone wins a party leadership but doesn’t have a seat in parliament, the convention is for another MP to step aside so the new leader can run for their seat in a by-election. Though that won’t be necessary in this case, since we’ll likely head almost immediately into a federal election.