If a spell causes you to lose the game the next time state-based actions are checked (by dealing damage to you greater than your life total, for example), that spell will already be in the graveyard by the time Lich's Mirror's effect happens. If it's in your graveyard, it will be shuffled into your library.