Maybe the Enterprise was so damaged that it traveled at very low speed. Mudd's communicator would be in range, if barely so?
It's a noticeable 1 light second delay between Earth and Moon communications. To be further out and have instantaneous communication is an accomplishment for a little hand-held device. The mean distances from the Earth to the Moon is 385,000 km (239,000 mi). That's quite a distance in itself.
I'm willing to entertain the suggestion that the communicator simply tied into the ship's systems like some Bluetooth device or how one's cellphone will automatically tie into a known wifi hotspot.
Hmm. I thought it was pretty explicit that the ship was already there?
No. According to the sequence of events, Harry contacted the miners prior to the Enterprise achieving orbit.
[Mudd's quarters]
MAGDA: Top space frequency of three nine. (hands over communicator)
MUDD: Rigel 12. Rigel 12.
CHILDRESS [OC]: This is Rigel 12. Come in, Enterprise.
MUDD: Well, this isn't exactly the Enterprise. My name is Harry Mudd. To whom have I the pleasure of speaking, sir?
[Bridge]
SULU: Power curve still dropping, Captain.
FARRELL: We'll make orbit, sir. A temporary one.
KIRK: Lay in. Computer?
SPOCK: We can sustain this orbit for three days, seven hours.
KIRK: More than enough time. Communications, have a representative of the Rigel 12 miners meet us here to discuss our needs. Beam him up first pass over their camp.
UHURA: Yes, sir.
The miners knew the Enterprise was coming, but the Enterprise hadn't achieved orbit yet.