Sugru is excellent for "potting" since you can mould it round the item and it supports itself.
Another method I used on the steppers on my lathe and dividing head, which have flying leads emerging from the motor, is to drill a hole at one end of a small plastic project box, pass the wires through the hole into the box, and glue it down on the side of the motor with Araldite. Then terminate the flying leads with terminal strip inside the box on to multicore cable run through a grommet, screw on the box lid, and if necessary use a tie wrap round the flying lead for strain relief. Will post a photo if I can find one.

This is the X axis drive on my VMB mill. It uses a Type 23 stepper so a bit bigger, you would need a smaller box. In this case the 8 flying leads from the motor needed some interconnect to put the windings in series, so they are soldered and heat-shrink sleeved, then the non-commoned ends connected to the choc bloc segments to connect to the leads to the driver – this could have also been soldered to save space. The leads were actually led in from the end of the box, and protected by moulding Sugru around them. At the other end the cable I made up has a spiral nylon binding, fixed at the otor end with heat shrink, and again moulded in Sugru. Box lid has been unscrewed to get this shot.
Edited By John Haine on 19/08/2021 12:00:28
Edited By John Haine on 19/08/2021 12:23:42