How can I write an if else statement in Twig based on commerce stock quantity?
This is very close - but it seems you are missing the actual stock level value from the object. Start by doing something like:
{{product.variation_field_stock_level.0|json_encode}}

Run it through a json cleaner to make it readable, like: JSON Cleaner
You will see this:
{&quot;#type&quot;:&quot;html_tag&quot;,&quot;#tag&quot;:&quot;p&quot;,&quot;#value&quot;:0}

Now the conditional will be:
{% if product.variation_field_stock_level.0['#value'] &gt; 0 %}
    {{ product.variation_price }}
{% else %}
    &lt;p&gt;Sold&lt;/p&gt;
{% endif %}