Hashem tells Moses to "lay his hand" upon Joshua
(27:18), then when Moses does, he puts both hands upon
him (27:23). Rashi says he does even more than he had been commanded.
Why in this case is he allowed to do more than he was commanded,
as opposed to when he struck the rock, rather than just speak
to it, and is then punished? Thanks!

Dear Elisheva Appel,

Here, Moses did more than he was told, whereas in the episode
of the rock he did something completely different.

With one hand, Moses conveyed to Joshua political and military
leadership, and with the other hand, spiritual grandeur. Hashem
commanded Moses regarding the political and military leadership
only. Moshe, on his own, blessed Joshua with the spiritual grandeur.

Jacob blessed his sons. Elijah blessed his student, Elisha.
They weren't commanded to do so. Here too, Moses blesses Joshua
with Torah greatness, though he wasn't commanded to do so. Since
Moses was giving of his 'own' holiness and spiritual inspiration,
he could give it as generously as he wanted.