What do you do when you don't know how you came to know something?
For purposes of citation in a paper, all you need is some appropriate source where the reader can find the relevant information.  It doesn't have to be the same source from which you originally learned it - indeed, nobody really cares how you originally learned it.

So this comes down to general literature search techniques: check standard textbooks, find other papers that use the fact and check their references, talk to collaborators or other experts in the field, ask on CS Stack Exchange, etc.  If you can find the original paper that introduced the idea, that's ideal, but a textbook that gives a modern presentation is also useful, and you can cite both.

If the fact is "common knowledge" in your field, it may not be necessary to give a citation at all.  Again, if you're not sure whether that applies to this particular fact, you can ask other experts in your field what they think.


  It is considered very bad practice to search for literature about something after the fact that you used it in your work. 


Says who?  Sure, if you're sufficiently well organized, it's nice to find references for all relevant facts as you use them.  But if you're not quite that well organized, or find that this would break up your workflow, I don't see anything wrong with going back to fill in references after the fact.  This is very common.