DISCLAIMER
UE5.1 this tutorial is partially outdated. Epic changed the way profileGPU lists shadowcasting lights so there is a slight change to the way you parse data. Look for ShadowProjectionOnOpaque instead of shadowmappass. Also light name is in a different line so you need to account for that too.
This tutorial describes how to get a list of lights that currently cast shadows.
It uses stock UE, requires basic knowledge of editor scripting and at the end provides you with a list of selectable light actors.
https://dev.epicgames.com/community/learning/tutorials/bJ8d/unreal-engine-listing-shadowcasting-lights