Does electrical box have to be nailed into side of stud
If the box is not required to hold the weight of a light fixture it need only be securely fastened.

For example, you can get a 3-gang "old work" box designed to be attached only to the drywall. Which one you pick can have more to do with what cable is coming into the box: NM vs metal jacketed.

It sounds like you have access to the stud since you have removed the old box and expanded the drywall. The box you picked happens to nail to a stud rather far back. But there are other options. It may be difficult to reach the mounting points of a metallic switch box but you can nail into the stud with a metallic masonry box instead.