Yes, you may do so, the key distinction that you have made in the question is the ball 'out' of the bunker. If the ball is still in the bunker you would be penalised two shots for grounding a club in a hazard. If the ball is no longer in the bunker you are in you may ground the club, but be aware, there is really no need to.
Chat with our AI personalities
because its a hazard and in the rule book section 13-4, it says you cant touch the hazard with your club prior to hitting the ball.
No, the only time you are allowed to ground your club in the bunker is when you are playing an actual shot. If you ground your club in the bunker prior to a stroke it is a two shot penalty.