Alter entity.user.canonical (/user/{uid}) route
There are at least two ways you could pursue to do what you're trying to achieve:


You can alter routes using a RouteSubscriber.
Listen for a event (likely KernelEvents::REQUEST), and respond appropriately.


The RouteSubscriber is probably a bit hard to do (I haven't written one yet, I just discovered their existence the other day), but is more in keeping with the older hook_menu_alter patterns from previous versions of Drupal.

The EventSubscriber is probably easier to write once you understand the event system (which requires some learning but is where lots of the future of Drupal internals is headed).