Suppose you frequently email a person about their work and ask them
questions. Can you use him as a work reference even if you do not
professionally work with him?
You can use anyone you choose as a reference. But the real question is - would this be a wise choice?
You could use the President of the United States as a reference, but unless you actually worked with her/him, it would be foolish to do so.
Similarly, you could use your internet buddy, whom you have never really met and have never really work with, but it might not make sense to do so. If a hiring manager called this person and asked about you, what insight could this person provide? If your internet buddy said "I've never met him." would that help or hurt your job candidacy?
In general, you want references who know you well enough, and have direct evidence of your work, and who will say really good things about your work ability when asked. Using anyone else is a risk.
At best, your email friend might be able to say "He sends a lot of emails, and asks good questions." But it's unlikely he has any direct evidence of your work ability. Is that the best you can do for a reference?