Try changing it to use strapi utils and a more defined model schema:
const utils = require("@strapi/utils");
/*** **/
const schema = strapi.getModel('plugin::users-permissions.user');
let userWithRelatedSanitized = await utils.sanitize.contentAPI.output(userWithRelated, schema);
It’s funny, your error actually helped me figure it out on my side. I wasn’t using contentAPI.output correctly.