The part that gives me the most pause here is "a much simpler and future-proof way to write one function." I haven't seen your code and have no understanding of the context of your change, but it doesn't sound like you fixed a bug, added a feature, improved performance, or otherwise did something that the project maintainers considered meaningful. I can see how submitting a pull request for an unsolicited change of this nature might not have left the best impression.
Many open source projects (and frequently closed source development projects too) aren't run like Wikipedia articles where everyone is encouraged to make small changes all the time. There's a non-zero cost that comes with any change: the time to review and test and approve it, the risk of breaking something (even with a robust test suite), creating something that fewer team members understand, etc... As a result, many projects aren't particularly big on changing things just because; there are an infinite number of ways to write any function, and nothing would get done if everyone regularly changed existing working code to meet their personal definition of "best" without justification. These are norms, and like all norms, they vary and are generally things you're expected to pick up through osmosis rather than be taught. If you were a recent graduate, it's likely that none of this was particularly apparent at the time.
Most pull requests address a more obvious need like fixing a bug, adding a feature, or improving documentation or testing, rather than changing a function to accomplish the same result in a different way if the maintainer doesn't see value in the change.
So I don't think it's inherently inappropriate to ever submit a pull request during the interview process (it certainly shows interest and enthusiasm), but from their perspective, they may have seen you as someone who is likely to rewrite working code without much justification, and then they, unfortunately, reacted negatively and condescendingly toward you. Which, helpfully, tells you a lot about them and what it would have been like to work with them.
Edit: this is several years later, but as this question continues to attract views and votes, I feel like I should clarify my point a bit. The concern the interviewer may have felt, especially if the benefits of your PR weren't apparent to them (one person's "simpler and future-proof" function is another person's "why did you rewrite my working code for no reason?"), was that it could have appeared like you were browsing the codebase looking for something to change arbitrarily for the sake of making a change. There was still no reason for the interviewer to react so condescendingly to a PR, but if it felt to the interviewer—even though I'm sure this was not your intent—like your change was submitted more to boost your prospects as a job applicant rather than to materially improve the project, it may not have left a positive impression.