I created a tool in ArcGISPro 3.1.2 which intends to copy layers to already existing Group Layer:

(Layers FC1 and FC2 should be copied to GL1).
Script tools has one paramter (Data Type = Group Layer obviously);

The script code is as following:
import arcpy
def script_tool(gl):
"""Script code goes below"""
m = arcpy.mp.ArcGISProject("current").activeMap
arcpy.AddMessage(f"I'm an object: {type(gl)}") #<class 'arcpy._mp.Layer'>
#gl=m.listLayers("GL1")[0] #if uncommented script will work well
#arcpy.AddMessage(f"I'm an object: {type(gl)}")
for l in m.listLayers():
if l.isFeatureLayer:
arcpy.AddMessage(f"Adding {l.name} to {gl.name}")
m.addLayerToGroup(gl,l,"BOTTOM")
if __name__ == "__main__":
param0 = arcpy.GetParameter(0) #read as object, not value
script_tool(param0)
The script fails with following information:
File "E:\GIS_DATA\ArcGIS\WIW\WIW.atbx#MoveLayers_WIWatbx.py", line 23, in script_tool
File "C:\Program Files\ArcGIS\Pro\Resources\ArcPy\arcpy\utils.py", line 191, in fn_
return fn(*args, **kw)
File "C:\Program Files\ArcGIS\Pro\Resources\ArcPy\arcpy\_mp.py", line 2593, in addLayerToGroup
return convertArcObjectToPythonObject(self._arc_object.addLayerToGroup(*gp_fixargs((target_group_layer, add_layer_or_layerfile, add_position), True)))
ValueError: <MappingLayerObject object at 0x0000019CBBEBB270>
If I uncomment line 7 and get GroupLayer object "manually" the script will work ok.
So why it doesn't work when GroupLayer object is taken from parameter?
BTW - I'm aware that I could do some workaround like
new_gl=m.listLayers(gl.name)[0] #gl is object from script tool parameter
which would work as long as there are no duplicate names of Group Layers in TOC. Still I'd be greatful if someone can explain to me what going on behind the scenes.