If muguy is right, then this warning is correct, and you may lose those pictures. Some pictures transferred from a computer can be viewed in Photos, but they can't be modified by Photos, so there may be some operations that produce a warning about those being at risk. You can tell if a picture is not in control of Photos by turning going to Edit mode-- these pictures can't be edited by Photos.
You may be able to transfer these picture files to a computer using the methods in the links provided by The Littles, but I'm not sure which of these work or don't on these types of pictures.
One way to preserve these orphan images is to save them to the Files app (Share>Save to Files,) and then in Files, use More(•••)>Select>[select some]>Done>Share>Save Image. This puts the file back into Photos in a way that can be controlled by the app. It also leaves, now, 3 copies of each picture, which will take up a lot of space. So you may have to deal with a small number at a time, delete the extras, and go again.
Is this what's going on with these 5000 pictures?