A couple of times when I started Homing one of the stepper motors did

A couple of times when I started Homing one of the stepper motors did not stop at the switch endpoint. It was hitting the mecanical endstop and still had power on. I suspect that I started Homing with that endswitch activated.
Is it so that the Homing cycle can start even if some endswitch is activated?

tinyG, tinyG2 or GRBL?
If tinyG, have you read thru https://github.com/synthetos/TinyG/wiki/Homing-and-Limits-Description-and-Operation#g282---homing-sequence-homing-cycle for what is “supposed to happen” ?
Is this a corner case issue, i.e. if you manually place the gantry well away from limit/homing switches, does it home properly?
Are there limit AND homing switches, or just homing?
Are you sure that motor polarities are set so that the limits will be hit when traveling toward a zero point?
What mechanical limit is being hit during your faulty homing operation: Z, X, Y, ?

I am using GRBL and for most of the times Homing works perfect.
I only use homing switches.
I have noticed that when I had problem the actual axes was closed to the endstop so the switch could have being activated.

Sorry, I don’t speak GRBL so I’ll have to just watch.
You might want to clarify what you mean by “endstop”.
Do you mean the travel extreme that is closest to “Home” or furthest away from “Home”.
If GRBL works something like tinyG, and you powered up your machine with the gantry mechanically sitting physically at (Xmax, Ymax), that would initialize the zero at (Xmax,Ymax). If you don’t have limit switches at the max ends, then homing might try to go beyond max a bit as it first backs off current position before starting its search for the the limit switch.