twig check if image style or view mode exists
You can check image style existence in a preprocess hooks like follows.

$variables['image_style_exists'] = (bool) ImageStyle::load($style_name);


Though it's better to validate user input instead.
Note that configuration entities like image styles or views can be selected through entity reference field which may perform such a validation for you.