Select Dynotopo field and check it as true
All objects have the use_dynamic_topology_sculpting property, which allows you to check whether or not dynamic topology is activated. Therefore your script could look like this:

import bpy


active_object = bpy.context.view_layer.objects.active

if active_object.mode == "SCULPT" and not active_object.use_dynamic_topology_sculpting:
    bpy.ops.sculpt.dynamic_topology_toggle()