Even if, as expected, Boris Johnson is elected leader of the Conservative party, it is by no means certain that he would automatically become PM.
When Theresa May goes to the palace to offer her resignation to the queen, HM will ask her who can command a majority in the HOC. It would only take a small number of Tory MPs to refuse to back BJ for it to be impossible for him to claim the support of the majority of the house.
This would very likely result in a general election, but there is another possible, albeit unlikely, scenario where someone else (not Jeremy Corbyn) can win cross party support and command a majority. If that happened TM would have to advise HM accordingly and that person (possibly Dominic Grieve or Yvette Cooper or, who knows, even the new Lib Dem leader) would be invited to form a government.