It’s because your varA in Jinja is a DateTime object, which does have a strftime method, whereas your automation script sets it to a string, which does not have the method. I haven’t done much work with variables, but I’m guessing the type will always be a string, in which case you’d have to convert it back to a DateTime. So the equivalent in Jinja would be:
{% set varA = now() | string %}
{% set varB = (varA | as_datetime).strftime('%Y-%m-%d') %}
{{ varB }}