If you have a basic path we can get route using router.no_access_checks service. Keep in my you have to have a leading slash
$router = \Drupal::service('router.no_access_checks');
$result = $router->match('/node/2');
In case you have URL object we can get route from it like this
$router = \Drupal::service('router.no_access_checks');
$result = $router->match($url->toString());