Have you tried to find out if the black squares are only appearing in edited versions of your photos? You may want to try to revert the problematic photos to the original. This will tell you, if the squares are caused by damaged data, for example transmission errors. I have seen such large black blocks when image files get damaged, that are in a highly compressed format, like JPECs or HEIC files. These formats are not having much redundancy, so a single flipped bit can cause a lot of damage. such damage could be caused by transmission errors or by a defective memory.
As the problem is appearing right after taking the photo, make sure, that no photographic stiles are applied by the camera.
Do you have another device, for example a computer? Then try to transfer the original image file to the computer to check, if the original is damaged or the rendering or display of your iPhone is causing the problem.
As a second test, transfer photo, that is looking fine on your computer to your iPhone, to check, if the iPhone can display the photo correctly.