Use Python CIM access as described below. A handy way to see what you want to update is to set it manually, then export the layer to lyrx and open the lyrx in a notepad to view the JSON.
## access your aprx
aprx = arcpy.mp.ArcGISProject("CURRENT")
## access the layout
layout = aprx.listLayouts("Layout Name")[0] # update your layout name
## access the mapframe
mapframe = layout.listElements ("MAPFRAME_ELEMENT", "MapFrame Name")[0] # update your mapframe name
## access the layer to update Page Query for
lyr = mapframe.map.listLayers("Layer Name")[0] # update your layer name
## get the CIM definition (like JSON)
lyr_cim = lyr.getDefinition('V3')
## update the pageDefinition
lyr_cim.pageDefinition = {"type" : "CIMPageDefinition","pageFieldName" : "FIELD NAME", "excludePages" : False} # update FIELD NAME, set excludePages to True or False
## update the lyr CIM definition
lyr.setDefinition(lyr_cim)
## save your aprx
aprx.save()