A stored spell (probably) has the same range as the normal version of that spell
There is nothing in Glyph of Warding's text that explicitly states a maximum or minimum range at which it can cast a spell. The Range for Glyph of Warding itself is "Touch", but that is presumably to create the Glyph, not for effects the Glyph creates. The Glyph itself can "cover an area up to 10 feet in diameter", but that does not necessarily mean its effects are limited to this area.
There is a small hint in the text that the Glyph can effect things which are not touching it. Specifically, amongst the possible triggers it states (PHB, p. 245 bold added)
typical triggers include touching or standing on the glyph, removing another object covering the glyph, [or] approaching within a certain distance of the glyph.
However, this does not tell us definitively whether or not the Spell Glyph can cause effects at any particular range. After all, the the Explosive Runes version of Glyph of Warding effects things in a 20 foot radius sphere centered on the Glyph, so a trigger of "when a creature comes within 15 feet of the Glyph" would be a reasonable (if often sub-optimal) trigger for that feature alone.
The biggest hint we have is simply the description of what happens when a Spell Glyph is triggered (PHB, p. 246, bold added):
The spell being stored has no immediate effect when cast in this way. When the glyph is triggered, the stored spell is cast. If the spell has a target, it targets the creature that triggered the glyph.
The triggering of the glyph will cast the spell you stored in it, in your case Greater Restoration. The spell will have all the qualities that it usually does, including range, duration, and effects.1
If Glyph of Warding changed features of the spells it "casts", its text would say so. Since it does not, the Range of the stored spell most likely remains unchanged. So a creature would need to be touching the Glyph of Warding in order to benefit from a stored spell of Greater Restoration, since Greater Restoration's range is Touch. If the stored spell had a longer range, that range would be used instead. For example, if you stored the spell Haste into a Glyph of Warding, the Glyph could target any creature that triggered it with a Haste spell as long as that creature was within 30 feet of the Glyph (the range of Haste being 30 feet).
1: The only feature of the spell we can be sure will change when it is triggered (besides "concentration") is its components: the components are necessary for "casting" the spell (so you presumably needed them when you "cast the spell" as part of the casting of Glyph of Warding), but we are already told that "the stored spell is cast" when the glyph is triggered without any caveats (which is good, since the Glyph has no hands to gesture somatically or mouth to speak the verbal components). So the components will be unnecessary when the spell is triggered, the same way it would be unnecessary to pay gold for an item that a spell magically created, even though that item usually costs gold at a store.
Careful Spell works just fine on Bones of the Earth
When a character is told to make a Saving Throw, said Saving Throw has been forced upon them. In the case of spells like Bones of the Earth, the Saving Throw hasn't been made "Optional": the creature targeted has simply been given the option to automatically fail it. They're still subjected to the Saving Throw, and they still suffer the consequences (which may or may not be beneficial in this context) for having failed it.
So it's perfectly fine for Careful Spell to be applied to this spell, or other spells that have Saving Throws that can be failed deliberately (like Zone of Truth).
There is an intersection of specific rules though
It's not clear whether the Sorcerer using Careful Spell to force a creature to succeed on their Saving Throw cancels out a creature that chooses to fail their Saving Throw, or not. They're both specific rules: automatically succeed vs choose to fail.
At my table I would generally rule the Careful Spell takes precedence, because it's specific to this casting of the spell, whereas the choice to fail applies to all castings of the spell. But I can't necessarily say your DM will rule the same. So while Careful Spell would indeed allow a character to automatically succeed at their Saving Throw, whether it prevents them from choosing to fail is an open question.
Best Answer
RAW: Yes, you can, IF that damage is unbeknownst to the target (and in most cases the caster as well). You could not tell the target to walk off a cliff, jump into the spike pit, or smash its face into your Paladin's Warhammer. You could however tell the target to walk down a hallway you suspect but are not certain may contain traps. Why? Because it wouldn't be "directly harmful to it", it would be potentially indirectly harmful to it. What if it doesn't trigger any of the traps you aren't even sure are (and may not even be) down there? So no, it could not be used as a foolproof trap detector because unless the GM tells you and you (your character) becomes aware there are traps in said hallway, the spell would not fail. Let's say you poisoned one of their 5 rations and then told them to eat one? You can't be sure which one the target will eat, so it's still indirect.
As for the in-universe thought process? You are exactly correct. Self preservation would cause the magical command to fail, to cease functioning, to not take effect. If the target is unaware that it needs preserve its own life from something that might occur as a result of following the given command, then there would be no need for self preservation, and thus it would follow your command.