My niece’s 2006 Honda Civic had an odd problem where it would randomly not shift into park. Sometimes wiggling the shifter around would allow it to work, but the issue occurred periodically for almost a year. My brother spend considerable time trying to resolve the issue, checking the shift solenoid and linkage. Eventually we looked under the vehicle and the issue was some small stones/gravel that had gotten lodged inside the shift linkage shield under the vehicle. The stones would interfere with the linkage movement. Removing the shield and cleaning out the stones completely resolved the problem.
Sorry I didn’t take a picture, but the silver shield is easy to locate if you find the shift linkage and follow its path to the transmission.