The fewer places the pad has to move, the less likely it will fall or slide off the bed overnight. As a result, moving the bed into a corner of the room eliminates two directions the pad can slide and helps ensure the pad will stay put as your sleep. Trapping part of the pad between the wall and the bed further secures the pad and creates more of a challenge for the pad to pull away from the wall when you move.
Elastic strips fit over the corners of the mattress pad and wrap around the corners of the mattress to form a durable support that holds the mattress pad in place and prevents it from moving. The strips are sometimes available in local stores in the bedding section, or you can order them. Using thick rubber bands also works but not as well as the strips that are specifically designed to grip the pad fabric via a fastener.
One reason the pad slides so much is the lack of friction between the mattress and the pad. Increasing the friction therefore helps the pad stay put when it is in use. A thin rubber pad grips the mattress pad from underneath it while also creating friction with the mattress, so the mattress pad is less likely to slide off. The pad is thin enough that it won't be noticeable, and you shouldn't feel a difference in the mattress or the pad when lying down. If you use a thicker pad, it provides firmer support for your body as well, which depends on your personal preference.
Double-sided tape temporarily secures the mattress pad to the mattress and holds them together when applied at the corners of the pad. It functions in a similar fashion to the elastic strips because it secures the corners of the pad to ensure the rest of it doesn't move, but the adhesive won't last as long as the bands will. Double-sided tape is probably the least practical solution, but it works well in the short term if you need it to. Likewise, safety pinning the pad to the mattress helps secure the pad but is also more likely to rip the mattress, the pad or both. It works temporarily but isn't recommended as a long-term solution.