Dynamical formation of a hairy black hole in a cavity from the decay of unstable solitons