To find Salesforce Profiles with Password Never Expires permission enabled, we have to check PermissionsPasswordNeverExpires on the Profile object/entity.
Please check the following SOQL which will retrieve all the Salesforce Profiles with the Permission Password Never Expires enabled.
SOQL:
SELECT Id, Name, PermissionsPasswordNeverExpires
FROM Profile
WHERE PermissionsPasswordNeverExpires = true
For Query Salesforce Permission Sets with Password Never Expires, check the following: