Answer:
The Prime Minister of Canada is not elected to that position, but rather appointed by the Governor General of Canada. There is no requirement that a Prime Minister be an elected even as a Member of Parliament. However, there is an unwritten constitutional rule that the Governor General must appoint a person with the support, or "confidence" from more than half of the Members of Parliament who are elected. Further, it is common for another member of the Prime Minister's party to resign and let the Prime Minister try to win her seat.
In cases where more than half of elected Members of Parliament belong to the same political party, the Governor General will typically appoint the leader of that party as Prime Minister. Otherwise, however, it is simply a question of which Member of Parliament (or Senator) can convince a majority of elected Parliamentarians to support her.
Sometimes, a Prime Minister who originally had the confidence of a majority of elected Members of Parliament subsequently loses that confidence. In such cases, the Prime Minister will resign. If the Governor General notices that there is someone else who is supported by a majority of MPs, then she may appoint that person as Prime Minister. Otherwise, she may dissolve the House of Commons, and call for a fresh election.