I know there have been some discussions about that topic, but I couldn't find a clear answer.
The rules intend that ranged attacks while hidden seem to be possible. Otherwise there wouldn't be feats like Skulker concerning this. Furthermore you wouldn't get Advantage while being hidden. Of course, you could argument that the "hidding" condition in this situations are only possible whily "lightly obscured" (e.g. by dim light), because Skulker also makes that possible.
However, here are my straight questions:
1.) Is it possible to hide behind an object/corner and make a ranged attack while being hidden?
2.) Do I have to step out for that or can I shoot while staying behind that object (e.g. by sticking to a wall/object and just peep around the edge of it).
Notice: If the answer concerning the 2nd question is "step out", attacks while hidden would no longer be possible with a Ready Action, because this would require movement.
Would be glad about answers!
Thanks in advance!
So within the rules, combined with Sage Advice and errata, you won't find an answer that says, "this is how it always works." And I think that's intentional. In part because I think it also has a lot to do with the group and playstyle.
So let me ask a few questions to start:
Have you seen the video where you're supposed to count the number of times a group of people pass basketballs? It shows how oblivious we can often be when we're focused on something. Like, for example somebody else trying to run us through with a sword. In the midst of combat people keep their eye out for danger, but if they are otherwise occupied, there are moments where their focus is taken.
Even if you know (and can even see) your enemy, you don't always know exactly when they will pop out to attack you. Much like whack-a-mole. Except the moles are trying to kill you. While somebody standing next to you is also trying to kill you.
Do you think it's possible that somebody could sneak behind two guards looking the other way? Without any cover or concealment other than the guards are facing the other way? It's a common enough trope.
So how about your 7-year-old daughter who you watch walk around the corner, not realizing that she stops and then jumps out to scare you? Oh, and then she does it again....
What about a fighter hiding around a corner, who jumps out to attack?
To me, these are all covered by Stealth checks in the game. And the possibility of success is there. In some cases with cover, others with concealment, and others in the open. The thing they have in common is that the perpetrator is unseen by the target (although in the case of whack-a-mole, that's not even true.
To rephrase your questions specifically, can you hide behind something and make an attack? In real life? If you had a nerf bow, could you? Would you have to step out, or could you lean out, stand up, or use some other variation to make the attack without stepping out?
For all of these questions, I think the answer is an unequivocal yes. So then the question is, how do we simulate these scenarios in the game?
The mechanics are already there. Stealth check against a (often passive) Perception check. If it's something that the target should see coming, you can give them advantage on their passive perception (+5). The first time, when you are truly hidden (your location is unknown), then I don't think there is any question that it's just a Stealth check. It really becomes a problem when people attempt to do it repeatedly.
One option, if the target knows you are there is they Ready an action to attack you when you pop out. Not only will it interrupt your attack and occur first, but in many cases I'd give them advantage on their attack because they were unseen to you until you popped out (unless you have a crack to look through, or something like that).
More importantly, any intelligent creatures will attempt to eliminate any advantage you or your party has. So a rogue that pops out twice and hides against is likely to be targeted by as many opponents as possible. At least in my game.
For your final question? Can you ready an action to pop out? In most cases I'd say no. It really depends on the circumstance, but a Readied action needs a trigger of some sort. So it probably can't be a visual trigger. If there's an appropriate trigger, then sure.
But circumstances are really the main question here. Are the circumstances such that as a DM you think they warrant a 25% advantage on their attack? For example, if they are popping up from behind cover, but their target has moved significantly from their last position; the advantage has probably been lost. Of course, if you have a crack or peephole to peek through, then I think you would. Not only would they not know exactly when you'll pop out, but they might believe they have successful foiled your attack.
I think it's important to be consistent (although that doesn't necessarily mean that it's the same answer every time), and it's also important to utilize such tactics against them. People will naturally use the tactics that are most advantageous where possible. Ranged weapons from behind cover is a very strong position, even if it doesn't grant advantage on the attack roll.
I've never actually had a problem with this sort of thing, simply because the opportunity to practice it is usually quite fleeting on my battlefield. It's a good way to draw targeted attacks. And that's been true from both sides (PC and monster).