A lot of questions asked on here are for very specific time periods and places or something you would not expect to have been recorded in depth (a recent question about Humpty-Dumpty for example). I can’t imagine there being an original text written in 1790 or whenever just to document a rhyme for the future
So, this question concerns something that often doesn't get much attention in this space but that's a crucial part of the work of historians in general: The essential skill of where to find information you don't know.
Historians need to read a lot. Like, a whole lot. a university system requires people to acquire a BA and an MA – a process that takes 5+ years – before someone will be regarded as able to produce a PhD thesis, which is the first piece of truly original research you will do. A PhD thesis by designs requires for the person to write it to do truly original research, meaning to answer a question about history that hasn't been asked and answered before and that is justified by truly expanding the wealth of human knowledge about the world. That isn't to say that people could do that beforehand but there is a reason most of us only start to attempt this after several years of training that forces you to truly read up upon history in an extensively in-depth way. Take f.ex. this prelim reading list on Modern Germany. This is what the University of Wisconsin thinks that you have to absolutely know and read when studying Modern German History. And those are 8 pages densely packed with books of several hundred pages.
This is intended to give you the background knowledge of your subject field in order to critically evaluate claims, know your area and – crucially in an academic – setting identify where desiderata lie that conceivably can be answered by your research. This whole process at the same time also teaches you another fundamental skill: Finding things you don't know quickly and being able to quickly familiarize yourself broadly with a topic. It shows you the value f.ex. of reading introductions to books since most of those will contain a discussion of previous scholarship on something in order to present why the question this specific book seeks to answer has not been answered previously and why it is justified in an academic sense to be answered – meaning, why it is relevant to our understanding of the past. It also teaches you the value of footnotes and bibliographies. If you only find a very shallow discussion of something interesting somewhere, go check out the footnote attached to it for more. Go look at the books cited in the bibliography.
Nobody starts from scratch within our profession and there is in virtually every case, someone who has already written on a certain topic or subject. Every historian stands on the shoulders of their predecessor, even if it is just in knowing which sources could be potentially interesting.
Furthermore, through the process of all this reading, you pick up another crucial skill: Taking notes. Since the process of, say, writing a PhD dissertation or even an MA thesis is a lengthy process that can not be done conceivably within a very short time, you learn to automatically take notes about everything you read in a certain fashion. Most of the time this will take the form of a precis or an excerpt, where we note who has written the book, what the main argument of the book is, how it is argued, a short summary of the chapters, and what kind of sources and literature are cited. How these are organized can vary but to use myself as an example, I currently have about 300 such documents on books I didn't necessarily all read from cover to cover but made notes on for my PhD dissertation. These are an invaluable resource for many a purpose but I often refer to them when writing something for this sub and have also started doing some for stuff I have read specifically for Askhistorians (f.ex. sexual violence in WWII is not my prime field of research but since it comes up often around here, I did write excerpts for the most important recent books for ease of reference).
Which brings me to the next thing: Websites like Jstor, Project Muse and others to which most people who work at academic institutions have access are databases of journal articles on a broad variety of subjects. These can be invaluable as a resource for finding info for questions here and reading a 12-20 page journal article to answer something here is something that can be done in a comparatively short time. For my recent answer on the Holocaust in Lithuania I knew some of the background but was able to fill out the details because I looked up journal articles in Holocaust and Genocide Studies that dealt with it in more in-depth manner.
The main thing about this forum is that unlike in an academic setting, we don't get to think up and design the questions we answer. This is the reason why it takes something around 9 hours to answer stuff because from the moment you see it when you have time to research it, etc. it simply takes time, including writing up something structured and sensible. It's also the reason why some questions go unanswered. Sometimes, questions don't have an answer in that we don't have sources or have never been tackled before because they aren't "interesting" in an academic setting to answer and while people have done this before (including myself) it is unlikely that someone will go out and do wholly original research just for this forum.
In short, we can find stuff because that's part of our education and training and we do have to read a whole lot and retain that information somehow.
Most of my knowledge comes from wide reading in my subject area or neighbouring ones (agricultural history, for example). So I can usually look at a question and go "I know I read something like that...". But I don't usually have much further detail off the top of my head unless it's right in my core research areas of the moment.
So the next step is to take a quick glance at my bookshelves (if I'm at home) or my LibraryThing listing, and see if there's anything relevant there. Often there is, and sometimes I have the reaction of "Wow, I didn't know I owned that". I've about a hundred books that are in some way about food and agricultural history, verging over into trade and economics, and then an indeterminate number more about generic history topics, mostly medieval, and then my wife's books on chivalry, medieval pageantry, and medieval literature and poetry. Maybe 200+ more, guessing by shelf space. So I can use all of those.
Then there's my stash of downloaded papers and ebooks, which is... extensive, and sometimes deeply specialised. It's upwards of 70 gigs, and I don't know how many files there are. So a hunt through there sometimes turns up relevant stuff, and very often I haven't even read the thing before, just squirreled it away for possible future reference.
And if those haven't produced enough material, then there's Google Scholar. On its own, Scholar is hard to use, and it can show you incredibly out of date stuff alongside the newest of the new, so you need some domain expertise in order to work out if what you're seeing is useful or not.
Finally, I know other people who know things, so I can shoot off an email or message to someone going "Hey, didn't you do a paper on Roman Food Logistics last year?" and usually get a reply of some useful kind.
On things being documented - you get used to the kinds of sources that are useful for your area. Most of medieval history features nobody writing down recipes, for example. But if you come sideways at it, and look at household accounts, letters from travellers, archaeological reports (particularly archaeozoology and archaeobotany), and in the case of Irish food history, medieval law texts, you can construct a lot of what was evidently there, albeit with the occasional frustrating gap.
So it's more "knowing where and how to look" than "knowing things" - but you need to know the pattern and shape of things to make any sense of what you find.
My answers come in maybe three categories:
Stuff I already know off the top of my head. I research and teach pretty much as a full-time job. So I have a lot of stuff rattling around in there that, if someone gives me the right question, will be triggered as a memory. I don't have a better memory than anyone else — it's just that I spend my days thinking and talking and writing (the latter two are very important for memory) about a lot of historical things. If you happen to ask me something that is on one of those topics, I can usually remember quite a bit of it, and even the source I got it from. Or remember enough to track down my notes or the original article or whatever.
Stuff I uniquely have the resources to find the answer to. On topics of my direct research (nuclear history) I have probably a terabyte of primary and secondary sources on my computer. More stuff than I've gone over personally, to be sure. But enough that certain types of questions I can quickly find the answer to. Again, this is very subject-specific — I can't do that for things that I don't do deep original research in.
Stuff I get interested in and so look up. Sometimes I'll see a question on here where I think, oh, that's interesting. I don't know the answer to that at all. (E.g., "What did early circumnavigators think about the loss of a day when sailing west?" — not something I had ever wondered before.) I wonder if, using my access to e-Resources, my general (not specific) research experience, and my general historical knowledge (which often helps me frame the kinds of answers that are likely to be found), I could come up with a plausible and informed answer to that rather quickly. And sometimes that is the case. Sometimes it is not (and you never find out about it, because I don't post anything). This only works for very specific sorts of questions — it cannot work for a question where you actually need to know a very broad literature to give a synthetic answer to.
As to your second question, " I can’t imagine there being an original text written in 1790 or whenever just to document a rhyme for the future" — we have what there is (and what we can find) and that is what we have. So maybe there is such a useful document. Maybe there is not. What history has preserved and what it has not is often exceedingly arbitrary even for modern things. One never knows.
I'm in a similar boat to /u/restricteddata on this. There are times when I remember things off the top of my head, and if you see an answer of mine where I only cite books and not page numbers, that's because I'm working largely off memory because I haven't got access to my books at the time. I do have the luxury of owning most of the books I've read on my areas of speciality, and so when I can, I do go off and check what pages in particular say what things. There have been times when I've looked things up specifically for an answer (my recent one on the opium trade being a key example) but rarely do I do so for questions I haven't already got a basic idea of how to approach.
And you'd be surprised with regards to the amount of original texts that say unusual things. There's one memoir by a civilian during the Taiping war which is full of laments about the death of his mother and how he seemed to develop an almost Oedipal obsession in the aftermath, constantly mistaking other women – including his own wife – for her. Thomas Taylor Meadows, in his supposed political treatise, The Chinese and their Rebellions (1856), often digresses into travelogue at inopportune moments, such that at one point he goes completely off the rails in talking about martial arts displays between opposing troops in the streets in Shanghai. One time I wrote an answer here starting off with one such piece of incidental information about a priest's clothes!