Dynamical formation of a Reissner-Nordström black hole with scalar hair in a cavity