The attribution, IMHO independent of the license, should be done in the usual manner.
State the copyright at the header of the file(s) or, if it is only a tiny part in a big file, you can also add or move their copyright statement to the documentation of the function.
Additionally you will want to amend the public copyright notice of your programme by theirs, indicating that parts (possibly which part) is their copyright.
If you modify the borrowed function you can indicate that by describing it as "functionality XXX based on work by..." or "...derived from work by...". You could also structure your credits in a similar way like OpenTTD with sections on current team, retired team and 'thanks to' where people are listed with significant one-time contributions (of whatever kind).
But the most important take-away here is: If you work in good faith to ensure that people (users and developers) can know who contributed what, you will be fine. Just communicate clearly to your users from whom you took code, and acknowledge that. If you maintain a VCS reasonably, and add a copyright message to files or functions, then the changes you made to the original code are readily documented.
All this IMHO is good practice also for permissive licenses like the MIT.
That said, and as you acknowledge yourself, you cannot legally include GPL-licensed code into your MIT (or other permissively-licensed) code-base. I really appreciate that you mind this difference as the GPL goes quite a bit beyond the requirements of the permissive licenses; it's a strong copyleft license, and often chosen on purpose. Additional to the requirement to credit the copyright holders as outlined above, the GPL requires, that ALL code derived from it is also offered to the recipients of the software under terms of the GPL or similar conditions. Thus, if you would want to include GPL-licensed code into an MIT-licensed codebase, you would have to approach the authors of the GPL-licensed code and get a special license where each allows you to release their code under MIT.