Unless the location of the images is changing or the images are being removed from the drive, Lightroom Classic should still be able to recognise the images. However, we would recommend you to take a back up of the images prior to defragmenting the external hard drive.
Defragmenting shouldn't change the paths/locations of anything, just consolidate the locations of individual hard drive storage blocks in a way that makes them faster and more efficient to read.
Making a backup like the Adobe response advised is always a good idea though, not just for this issue - I've lost hard drives before in such a way that they were corrupted beyond the ability to recover the files on them, so I always worry about a fire/theft/disaster wiping my drives. It's worth it to invest in a good online/cloud storage option (either Adobe's native option or a 3rd party service - lots of working pros seem to swear by Backblaze: https://www.backblaze.com/ )