I think the question has the order of events confused, as well as the point in time when the flashback occurs.
Shane already knows Walkers exist, though the world may not have gone completely crazy yet, he's there to get Rick. He secures the door and puts the bed in front of it to protect him from the walkers and, perhaps, mask the room from the rapid soldier searches (maybe they won't be thorough). Perhaps more importantly, he takes with him a peace of mind knowing he 'did what he could' rather than outright abandoning a friend to a hopeless situation.
Shane knows Rick isn't dead, that's a lie he created out of what he felt was necessity.
Season (or Series) 1 Episode 6 opens on the scene in question. It actually opens with Shane emerging from Rick's room somewhat frantic, not arriving unsuspectingly for a general visit with flowers (I think this was from a different visit in an earlier episode?).
Events unfolded as thus:
- Shane hears commotion outside Rick's room and opens the door. Several people stream by and there's some yelling. He pulls a nurse out of the passersby and pleads with her to help him. She's panicked, and unhelpful. He didn't ask her what was going on, he recognized things were ramping up, and he needs to move Rick.
- Looks around and others are rushing around. There's a military presence.
- Rushes to the end of the hall to get a gurney, spots military personnel holding up civilians (then shoot them).
- Rushes back to the room with the gurney.
- He picks Rick up, then realizes he's connected to equipment.
- Goes to check the equipment, looking as if to find a way to take it with them.
- The door opens by a soldier, and Shane ducks behind the bed. The environment is unsafe and patrols appear to be taking everyone out.
Up to this point, Shane appeared fully intent on getting Rick out of the hospital, but he's been spooked by the military (and I'm sure knowing there are Walkers about isn't helping).
- He begs Rick to wake up, or give him a sign. I think he's searching for a reason to continue pursuing his evacuation; to justify the risk.
- There's an explosion and the power goes out, taking Rick's monitoring equipment with it.
- Shane checks Rick's heartbeat (is this the sign? has he died?)... no, he's alive, Shane has to do something or make a difficult decision.
- He leaves the room and starts down the hall with gun drawn. We're not sure if he was leaving or planning to secure a path, though I think it was the latter.
- On looking behind him at the other end of the hall, Walkers are coming. Times ticking and he's going to be trapped.
- He goes back to the room, looks in at his friend one last time. Pulls the door shut, and barricades it with the gurney.
Italics in the above are my inference.
In a conversation between Lori and a drunk Shane later in the same episode, Shane:
- Recounts the craziness
- Says he listened for a heartbeat but didn't hear one.
- Says he had Lori and Carl to think about, and had to get them safe to Atlanta, and then
- "If you had thought for one second that he was still alive, would you have come? So I saved your life. You and your little boys, that's what I did."
I think in that single statement he reveals something significant... He believed Rick had to "be dead" in order for him to save Lori and Carl. Had he told Lori the truth, she wouldn't have left. She would have tried to get to Rick; to save Rick. He lied to save them.