Taking the question literally, how to learn (La)TeX inside out. To start at the bottom:
[Skipping Boolean logic, transistors, computer architecture, operating systems, etc…]
There is a program called TeX, written by D. E. Knuth, for which you can read the (documented) source code with texdoc tex (also published as Volume B of Computers and Typesetting), and the user manual (The TeXbook = Volume A). (Another independent documentation is TeX By Topic.) If you decide to read the source code, you'll also have to know (a subset of) the Pascal programming language, and Knuth's WEB literate programming system.
Next there is a program (collection of TeX macros) called LaTeX, originally written by Leslie Lamport and then by others, for which you can read the (documented) source code with texdoc source2e and the user manual in the (printed, real) book LaTeX: A Document Preparation System, and other books (The LaTeX Companion, lshort, etc; see questions on this site).
Next there are thousands of programs (aka packages, collections of macros that build on TeX, LaTeX, and other packages), written by various people, for use with TeX/LaTeX. They have varying quality of documentation in their user manuals, and varying quality of documentation in their source code.
[Omitting extensions to TeX like eTeX, pdfTeX, XeTeX, LuaTeX, etc.]
[Also omitting what happens before or after the core work of TeX is done: input encodings, fonts (OpenType and otherwise), DVI drivers or PDF viewers, etc.]
So when faced with a particular macro or behaviour you'd like to know more about, it could come from any of these sources. You can start at the top:
First, see if the definition is in any of the packages. To know which package's source code to look at, first you can get a list of all the package files that were opened by the TeX program: this you can do with pdflatex -recorder and looking in the <jobname>.fls file, or with mkjobtexmf, or a bunch of other solutions. Use a crude grep or whatever, to search for your macro in those files.
Next, check whether it is part of LaTeX itself: you can grep in latex.ltx.
Finally, check whether it is part of TeX itself: you can look in the index to the TeXbook, say.
Unfortunately, there isn't a better solution, such as TeX recording where it encountered the definitions of macros.
Example: For \textsuperscript, you can first check that it's not defined in any of the packages (as might happen, depending on the set of packages you've included), then find its definition in texdoc source2e:

And you can repeat the procedure for the definition you find, namely here \DeclareRobustCommand, \selectfont, \m@th, \ensuremath, \mbox, \fontsize, \sf@size, \z@. And repeat for things you find in their definitions, etc. Of course, many of these definitions (such as the one for \sf@size) only make sense in light of other definitions or what is being expected in certain contexts, so you need to understand them as well.
texdoc <packagename>to find its documentation. To learn about TeX the language, you should read the TeXbook (a real book) and the online TeX by Topic. (texdoc texbytopic). The documented source of the latex kernel is insource2e.pdf(texdoc source2e). – Alan Munn Apr 25 '18 at 03:09latexdefcommand, and friends may be of interest. For example,latexdef textsuperscriptreturns\textsuperscript: macro:->\protect \textsuperscript, which it then expands further to\textsuperscript : macro:#1->\@textsuperscript {\selectfont #1}. – Apr 25 '18 at 04:24