oh this is a 3Ø motor? why are you using #8 wire? thats way overkill
FLC for 230v 5HP 3Ø motor is 15.2a which means 19a rated wire. so you really only need #14 THWN in pipe.
Also, why bother adding a point of failure to the mix? if the wires are too short, just run some new ones. but if you must, just use wire nuts in a j box. not sure why you want to throw a breaker panel in the mix
also if this is further than 50' form and not within sight of the breaker panel, then you will need a local disconnect