To check this we need to use router.admin_context service
if (\Drupal::service('router.admin_context')->isAdminRoute()) {
// Do something here.
}
We also can check a specific route
$route_provider = \Drupal::service('router.route_provider');
$route = $route_provider->getRouteByName('user.page');
if (\Drupal::service('router.admin_context')->isAdminRoute($route)) {
// Do something here.
}