Sun object not moving when Rendering Animation
It seems that during rendering you need to use the depsgraph so that you obtain an evaluated object.
Don't know why this is not useful when just playing the animation.
So add this line:
sun = sun.evaluated_get(depsgraph)

In the complete function:
@persistent
def sun_handler(scene, depsgraph):
    if &quot;Sun&quot; not in bpy.data.objects:
        create_sun()
    sun = bpy.data.objects[&quot;Sun&quot;]
    sun = sun.evaluated_get(depsgraph)
    print(scene.frame_current, sun.rotation_euler)

A link to the documentation if needed.
For information, I've asked on blender coders and had an answer by dr.Sybren:

The difference is caused by the render engine using its own dependency
graph, which is not marked as 'active'. As a result, it does not copy
animated values back from evaluated to original objects.

This behavior is confirmed to be intended.