You ask, when storing simulacrum in a glyph of warding, which creature gets duplicated
Of your two scenarios, it is more reasonable that the target of simulacrum is stored when the glyph is created, as opposed to duplicating the creature triggering the glyph; for details and reasoning, see below.
However, the real answer is that the DM and the player should work together to realize the player's vision in a way that makes the game fun for everyone. Some scenarios are presented below.
But before we get to any of that, how does storing simulacrum in a glyph of warding even work?
DM Adjudication Required
Multiple issues involving storing simulacrum in a glyph of warding need DM adjudication; among them, casting time, material components, target of simulacrum, storing of the glpyhed simulacrum, multiple simulacra, controlling the simulacrum, and perhaps even using wish are all issues, which are all discussed below.
Casting time
Glyph has a casting time of 1 hour. Simulacrum has a casting time of 12 hours.
Glyph says:
You can store a prepared spell of 3rd level or lower in the glyph by casting it as part of creating the glyph.
It's a little messy to cast a spell that takes 12 hours "as part" of a spell that takes 1 hour.
It's reasonable for the DM to adjudicate that when glyphing a spell longer than an hour, the casting time of glyph expands to the casting time of the glyphed spell. (Or perhaps that the casting time is that of both spells added together.)
However, the spell does not explicitly cover this situation, so the DM must adjudicate.
The DM could adjudicate that you just can't glyph spells with a casting time greater than an hour. That is not completely unreasonable.
An argument in favor of this is that glyph says its casting time is an hour. If it could be longer, it would say so.
The DM could also adjudicate that the initial casting into the glyph takes no appreciable time at all; after all, glyph says:
When the glyph is triggered, the stored spell is cast.
Which is the real casting of the glyphed spell? The casting into, or the casting out of?
So, the DM could also rule that the casting of simulacrum from the glyph takes 12 hours.
So the DM has some choices to make here. Of the options, expanding the casting time of glyph to 12 hours (or 13), is the most reasonable, but counter-arguments exist.
Other questions have addressed glyph casting time. In general they support the notion that the casting time of glyph expands to include the glyphed spell. However, it is inescapable that the rules do not say, and so the DM must adjudicate.
Storing long casting time spells in a glyph
Can you store a spell that takes longer than 1 action into a glyph of warding?
Glyph of Warding and Teleportation Circle
Material components
The material components for simulacrum are:
snow or ice in quantities sufficient to make a life-size copy of the duplicated creature; some hair, fingernail clippings, or other piece of that creature's body placed inside the snow or ice; and powdered ruby worth 1,500 gp, sprinkled over the duplicate and consumed by the spell
The DM may need to adjudicate whether the snow or ice and body parts are specifically required.
The PHB says:
If a spell states that a material component is consumed by the spell, the caster must provide this component for each casting of the spell.
A rules lawyer might argue that the snow or ice and body parts are not in fact "consumed" by the spell, but are left over, therefore a spellcasting focus or component pouch can substitute.
To me it's clear, the spellcaster must supply the snow or ice and body parts, and "consumed" or no, the specificity of the spell description overrides the generality of the pouch/focus rules, but if in a discussion between DM and player there is question, then the DM will need to adjudicate.
This question addresses the issue of whether the snow or ice and body parts are consumed:
Which components for the Simulacrum spell are consumed?
Target of simulacrum
Glyph says:
If the spell has a target, it targets the creature that triggered the glyph.
On the other hand, simulacrum clearly says that body parts of the duplicated creature need to be provided (emphasis added):
snow or ice in quantities sufficient to make a life-size copy of the duplicated creature; some hair, fingernail clippings, or other piece of that creature's body
It is clear that glyph specifies a target at the time glyph is triggered, and simulacrum requires the target be specified when supplying material components. To my reading, the requirement of the material components to tie simulacrum to the target overrides the targeting of glyph, but this is a contradiction that the DM will have to adjudicate.
There are numerous questions here on rpg.se exploring glyph targeting. An example:
Can a spell with a target of Self be stored in Glyph of Warding?
Storing of the glyphed simulacrum
Another issue, which I didn't even think of until reading Nobody's answer, is, when casting simulacrum into the glyph, where does the simulacrum go?
Glyph says:
You can store a prepared spell of 3rd level or lower in the glyph by casting it as part of creating the glyph.
If you accept that simulacrum is fully cast being cast into the glyph, then, in the cast spell is stored in the glyph (it says so), so somehow the created simulacrum is also stored in the glyph. I don't think it's much of a stretch to accept that that's how it works, but the spell doesn't say, so DM adjudication is needed.
Multiple simulacra
Simulacrum says:
If you cast this spell again, any duplicate you created with this spell is instantly destroyed.
Glyph says:
The spell being stored has no immediate effect when cast in this way. When the glyph is triggered, the stored spell is cast.
Does a creating a second instance of the glyphed simulacrum destroy the first instance of a glyphed simulacrum?
The DM will have to adjudicate this.
One interpretation is that the initial casting of simulacrum counts in terms of duplicates, and so even casting simulacrum into the glyph destroys any previous duplicates, whether glyphed or not. A supporting argument is the phrase in simulacrum "if you cast this spell again".
The counter-argument is that the simulacrum spell is not actually "cast" until the glyph is triggered. A supporting argument is the phrase in glyph, "the spell being stored has no immediate effect". Therefore multiple simulacra could be stored away.1
I think the reasonable answer is that you only ever get one duplicate, and as soon as simulacrum is cast into the glyph, any previous simulacrum is destroyed, whether glyphed or not, but there is enough ambiguity in the phrasing of the two spells that DM adjudication is required.
Controlling the simulacrum
Assuming the issues above are resolved, the DM will need to adjudicate what the simulacrum actually does, once created by the glyph.
Simulacrum says:
The simulacrum is friendly to you and creatures you designate. It obeys your spoken commands, moving and acting in accordance with your wishes and acting on your turn in combat.
The player may just assume that once created the sim will act as the player directs, as an additional player character. The quote from the spell says that the sim "obeys your spoken commands", which implies the caster is with the sim, which is likely to not be the case if glyphed, although "moving and acting in accordance with your wishes" is perhaps a bit more ambiguous. However you parse the sentence, it seems unlikely that the description of sim was written with delayed implementation via glyph in mind. The DM will need to adjudicate.
Using wish
Commenters have brought up wish.
Wish can be used to duplicate simulacrum:
The basic use of [the wish spell] is to duplicate any other spell of 8th level or lower. You don't need to meet any requirements in that spell, including costly components. The spell simply takes effect.
First of all, we'll recall that wish has three forms: the "basic" form, duplicating a spell (described above), the "alternative" form, specified as a list in the spell, and the "beyond the scope" form, in which you state your wish to the GM.
We're only discussing the basic form of wish here. Surely the "out of scope" form can be used in this case, but it requires DM adjudication.
In the basic form, it seems reasonable that wish eliminates the casting time, the snow or ice and body parts, and the costly components of simulacrum.
But does it eliminate the target of the simulacrum? The wish spell is not clear on what is meant by "requirements". It is not detailed, the DM will need to adjudicate.
Specifically, the DM would need to determine, can an arbitrary target be specified, using the basic form of wish? I believe not. If an arbitrary target can be specified, then the target need not be "within range", a "beast or humanoid", or currently alive, or anything else. You may certainly use wish to wish for simulacra of "the three celestial rulers told of in the story I read", or for simulacra of "the demon lords of Hell". You can wish for these things, but you are no longer duplicating a spell, you are asking for something beyond the scope of the basic use.
In other words, the basic form of wish causes the duplicated spell to "just take effect" and eliminates the need for material components, but it does not fundamentally change the nature of the spell being duplicated. That is what the beyond-scope form of wish is for.
As NotArch says very succinctly in this answer regarding the basic use of wish, "If you change the spell language, it's not the spell".
My conclusion is that the DM would need to adjudicate using wish to cast simulacrum; the language of the spells just aren't precise enough. My ruling would be that wish supplies the material components, but that the phrase of simulacrum, "one beast or humanoid that is within range for the entire casting time" is an integral part of simulacrum and not a "requirement", and thus cannot be bypassed by the basic form of wish, and would require the beyond-scope form of wish. However, the spell does not say, so DM adjudication required.
Finally, regarding wish, the caster may want to use wish to simply duplicate glyph with simulacrum as the glyphed spell. The caster can use wish for that, but using the basic form, at best the caster can get only the RAW combination of glyph and simulacrum, and again, DM adjudication is required.
This question discusses the requirements that wish can ignore:
What exactly is ignored in the "requirements" of a spell when Wishing for it?
Adjudicating the combination
The DM may be able to reach a satisfactory conclusion by just working through the issues I brought up above, and coming up with something that makes the game fun for everyone involved.
I think there is a better way.
First of all, I think RAW is inadequate here. It is just flat-out not up to the task of combining these two spells. That's okay. The rules can't cover every situation, and so that's when the DM steps in with rulings over rules.
In this case, the DM and the player should work together to figure out what the player is after. If what the player wants can be done in a way that's fun for everyone, then the DM and player can work together to make that happen.
In-game Research
@KorvinStarmast pointed out in a comment that this stunt requires two 7th level spell slots to pull off. If the DM and player involved are in a campaign expected to reach the level necessary for this trick, but the character involved does not yet have the necessary power, it could be an opportunity for in-game research. The "research" can be hand-waved to take up a certain amount of downtime and/or financial or other resources, or the DM and player may want to play it out to some extent.
Sometimes players just want to know how things work (I know I do), and it may be that sometimes the real answer, from the DM's perspective, that's complicated to figure out, and it isn't relevant any time soon, and we have other things to worry about. Working with the player on ongoing in-game research is a way to forestall the DM having to answer every theoretical question whenever the player thinks of it, but still leaving the door open to future discussion.
It may be that a way to realize the player's vision is for the DM and player to create a custom version of the spell. Also, there is precedent in the game materials. I won't cite specifics, but there are published examples within the official material of NPCs who have crafted personal versions of simulacrum. If I were Wendy the Wizard, I would think it totally cool to have Wendy's simulacrum as a spell.
It may be a useful plot device if such a spell costs the character in-game time and resources to research this.
Home-ruling and custom versions of the spells
What is the player's vision? The player's intention may be any of these, or something not covered here:
- Circumventing duplicate simulacra restrictions
- Quick-casting simulacrum
- Setting up some sort of defense
Whatever the player's vision, rather than adjudicating these two spells ad nauseum, they can just work out a home-ruled solution, or a custom version of the spell, to the extent it can be done that keeps the game fun for everyone.
Conclusion
TL;DR Combining glyph of warding and simulacrum is complicated; no amount of rules analysis will yield a RAW answer, because the rules just don't say; The DM will have to adjudicate multiple issues; of your two scenarios, duplicating the target when glyph is cast is the somewhat more reasonable answer; really, the take-away should be for the DM and player to work together.
My conclusion is that DM adjudication is needed, which is no surprise at all with simulacrum and glyph of warding.
To your specific scenarios:
Does the glyph/simulacrum combination duplicate the caster at initial casting
This is the most reasonable of the two scenarios, given that simulacrum requires you to specify the target at casting. Some DM adjudication is required.
An issue is casting time, as discussed above. Another issue is "If you cast this spell again, any duplicate you created with this spell is instantly destroyed", which to me means you only ever get one sim at a time, whether it's stored in a glyph or not. Also of concern is the statement in glyph that "it targets the creature that triggered the glyph". This is at odds with how simulacrum works. The DM needs to adjudicate.
Does the glyph/simulacrum combination duplicate the target of the glyph
This is the more unreasonable of the two scenarios, given that simulacrum requires you to specify the target at casting. Some DM adjudication is required.
Of specific concern is that simulacrum requires the target to be present for 12 hours during casting, and requires body parts of the target, and that doesn't make much sense when simulacrum is triggered from a glyph.
Work together
Really though, the best answer is for the DM and player to work together to figure out a result that works for the game.
As the DMG says, "The rules don’t account for every possible situation that might arise during a typical D&D session." I think this is a perfect example. The player has a vision. The rules really just don't cover it. The player and the DM can work together to come up with something for their game that is fun and memorable. Sounds great.
1Note that allowing multiple glyphs to each contain a casting of simulacrum might allow a clever caster to chain, say, a dozen (or a hundred, or a thousand) glyphs containing simulacrum, with each directed to cast some spell upon being created; directing them to do so is left as an exercise to the caster, but one can imagine a chain of glyphs going off in succession, each simulacrum casting meteor swarm (or anything else) before being destroyed as the next sim is created. The DM may want to consider limitations if such shenanigans are a concern.