There are no rules that would make it more difficult for one creature to detect both the rogue and dwarf.
Any attempt to Hide is a rolled Stealth check. Hiding after an attack is not generally possible.
Your Stealth immediately ends after you make an attack roll, whether or not the attack is successful.
Narratively, you may have stuck around for too long to see if your shot landed, or taken too long to line up your Sneak Attack, giving the enemy time to spot you. Remember, each round of combat is about 6 seconds long. Alternately, the creak of the door as you bump it, your shadow, and the twang/whiff sound of your ranged weapon are all potential foils to your logic.
It may help to remember that anyone with any class levels and any creature that survives in the wild is probably used to dealing with the potential for battle. Good GM's may even apply penalties that you're describing to NPC's that wouldn't be prepared for such an attack. But even basic combat awareness includes mentally tracking everybody that you can.
Unfortunately, being behind the Dwarf and/or a door is simply not enough to avoid detection.
Hide behind other Creatures
Normally the soft cover provided by other creatures is not sufficient to allow you to attempt a Stealth check. Soft cover provided by creatures at least one size category larger than you does allow you to attempt Stealth checks against other creatures not already aware of your presence at a –10 penalty.
As well, being on the opposite side of the enemy from the Dwarf doesn't usually help. There are optional rules in D&D 3.5e for Facing that I have never seen used in Pathfinder, personally. All the same checks are still made, but if the target is facing the wrong direction, there is a penalty applied.
Side note, you do not gain or provide Flanking benefits with a ranged weapon (except with very specific abilities.)
When making a melee attack, you get a +2 flanking bonus if your opponent is threatened by another enemy character or creature...
You threaten all squares into which you can make a melee attack...
You seem to want a narrative combat, but Pathfinder leans more toward simulationism. There are mechanics, which I address in your related question, that allow you to accomplish the scenario you describe.