iPhone’s silent switch button may fail over time. Among the symptoms are random switching and unresponsiveness.
First of all, we recommend to carefully clean the switch. There are several tutorials on YouTube, so we won’t describe the procedure. If you are afraid to break something, visit an Apple Store, they do this procedure (in my experience even free of charge).
If cleaning didn’t help, Apple does replacements of the defective devices only if the warranty has not expired.
It’s highly unlikely that Apple will launch any service program, although the problem is very common.