Not to say it can't happen. For example, if you make cool features for Gitlab, they may want to reserve it for the paid version but they won't be able to (I hope) unless you were an employee, causing you to surrender your copyright for said developments to them.
Still, I think you'd be setting yourself up for disappointment, if you only do that work with the expectation that they would eventually hire you, when they have given no indication that they would even consider it. It's too much investment with little to no guarantee of returns, and most benefit of the work is gratuitously given to someone else.
It might be better to spend that free time to build a portfolio of independent projects to showcase to potential employers. Those projects would have your name on them instead of some company's, and they make it easier to judge the quality of your work by potential employers. It's easier to judge the quality of a complete project, as opposed to a few commits here and there in a project that's been worked on by many people.