Apparently, ma->paint_active_slot is always in sync with the current active texture node in nodetree.
So for the value set in ma->paint_active_slot to remain unchanged, the texture node it represents in nodetree must also become active.
To this, rna_Material_active_paint_texture_index_update searchs the node corresponding to ma->paint_active_slot and activates it.
The problem was that rna_Material_active_paint_texture_index_update did not search for texture nodes that are inside node groups (unlike fill_texpaint_slots_recursive).
The solution was to do a recursive function similar to fill_texpaint_slots_recursive and not ignore nodes inside groups.
Ref T67597
Related commits: rBf745564e, rB86aa621