I originally posted this for someone who called asking for advice, but I am leaving it here in case it helps anyone else.
When you get a bafang hub motor, it comes with two “torque” washers, which fit over the axle and have a tab that slots into the drop out. They firstly help to stop the axle turning, and secondly act as a spacer to bring the wheel width up to the width between the drop outs.
The following photographs show the location of the washers before putting the wheel into the frame, and in situ in the bike. See how the washers are between the frame and the wheel, and how the tab goes into the drop out AFTER the axle. This ensures the axle straight sides get maximum purchase inb the drop out to stop axle rotation, and the torque washers add their bit of anti rotation.
If you put them on the outside, the freewheel will jam against the frame, and will stop the wheel aligning in the dropouts and brakes properly.