"Tails" was always Miles Prower's nickname—it wasn't given to him by any single character in a specific moment.
The name is a play on his two tails, and it's simply stuck with him throughout the Sonic series.