Why the entry-Variable doesn't exists after search?
Yeh this a common problem I've run into as well.
The issue is the entry variable only gets set when Craft is routing to an entry that's created in the CMS. Since you're routing directly to a template, Craft can't populate the variable.
I can think of a couple workarounds:
If your search form page is defined in the CMS, just grab that (or another page):
{% set entry = craft.entries.section('whatever').slug('search').one() %}


Another option is just to modify your code for fallbacks:
{% if entry is defined %}

    {% if entry.seoPageTitle is defined and entry.seoPageTitle != null %}
      {% set metaTitle = entry.seoPageTitle %}
    {% else %}
      {% set metaTitle = entry.title %}
    {% endif %}

{% else %}

    {# set the fallback from a global for example #}
       {% set metaTitle = defaults.metaTitle %}

{% endif %}

That's a lot of code for basically setting variables. What you could do to help clean this up is to use the null-coa­lesc­ing operator or default filter in Twig:

{% if entry is defined %}
      {% set metaTitle = entry.seoPageTitle|default(entry.title) %}
{% else %}
      {# set the fallback from a global called &quot;defaults&quot; as an example #}
      {% set metaTitle = defaults.metaTitle %}
{% endif %}