There have been a variety of reasons and circumstances that lead to title shots after losing.
Randy losing LHW title fight then next fight for HW title. Before that though he lost HW title fight then next fight was for the LHW Interim title.
Nick Diaz lost Interim title fight, next fight with GSP for WW title.
Chael Sonnen obviously as mentioned.
Dan Henderson lost LHW title fight to Rampage and his next fight he lost MW title fight to Spider. Obviously unique situation since he was 2 division Pride Champion unifying titles.
BJ Penn, Shogun and Frankie Edgar lost title fights and then got immediate rematches.