Dimir Doppelganger becoming Lazav, Dimir Mastermind
Assuming your grizzly bear scenarios are either/or (and you're not doing one after another)...

You are correct. The card will come back as either a Lazav copy or a Doppleganger copy and it depends entirely on which card's copy ability you use.  

It's the ability itself (of either lazav or the doppleganger) that causes the copy to retain the previous abilities, because it uses the wording: "gains this ability."