Is it legal to go under the net, on the other players side in indoor volleyball to play a ball that was going out? From my understanding, you would have to hit it around the net, then another team member would have to hit it over the net and as long as you don't interfere with the other team (or it isn't a dangerous play) - it is legal. Is that correct? Does the same apply to Sand Volleyball? (both 2s and 6s)
In the diagram you've drawn, this would result in losing the point. The ball has passed entirely to the other side of the net through the crossing space so your team is no longer allowed to play the ball.
Quoting from Rule 9 of the 2015-2016 Rules of the Game:
Each team must play within its own playing area and space (except Rule 10.1.2).
However, if the first hit had passed outside the antenna, then this would be a legal play, although for indoor volleyball, the player passing under the net may not touch the opponent's court. They can either go under the net between the posts and outside the opponent's court, or around outside the post. This is Rule 10.1.2 as referred to above:
The ball that has crossed the net plane to the opponent's free zone totally or partly through the external space, may be played back within the team hits, provided that:
the opponent's court is not touched by the player;
the ball, when played back, crosses the net plane again totally or partly through the external space on the same side of the court.
The "external space" is that to the side of the net, so this means that the ball cannot be returned to the first team's side of the net over the net, but must instead go around it.
The beach volleyball rules are essentially identical except there is no restriction on touching the opponent's court. The FIVB does not produce any rules for 6 vs 6 beach volleyball, so you'd need to refer to the rules for whichever competition you're playing under for that.
The ball to be playable on other side, needs to go to the other side partially on the outside of playing area (that is at least partially above the antenna or further away from the court to the side) both on the way out (first hit) AND on the way back in (second hit). This would answer your comment to the accepted response.
Then the third hit needs to be totally in the playing area (between the antenna completely and not at all above the antenna, as this is equivalent to a ball hit out (it it was lower it would touch the antenna).