In the macro, define a dict then report it in JSON format. That format doesn’t support datetimeobjects so report them as datetimestrings in ISO format.
The revised macro:
{%- macro dates_sun() -%}
{%- set a = (states('sensor.solcast_pv_forecast_heure_du_pic_demain') | as_datetime | as_local + timedelta(hours=-1)).isoformat() -%}
{%- set b = (states('sensor.solcast_pv_forecast_heure_du_pic_demain') | as_datetime | as_local + timedelta(hours=+1)).isoformat() -%}
{%- set c = states('sensor.solcast_pv_forecast_previsions_pour_demain')|float(0) -%}
{{- dict(start=a, end=b, power=c) | to_json -}}
{%- endmacro -%}
Testing the revised macro:
{% set x = dates_sun() | from_json %}
{{ x.power }}
{{ x.start }}
{{ x.end | as_datetime }}