why \usepackage{tablefootnote} puts the footnote at random locations

Footnotes at the bottom of the page to a float will produce this undesired effect since the float might float away to another page. In case footnotes to tables (or floats, in general) are really required, it's better to use footnotes immediately after the float which can be obtained using, for example the threeparttable or ctable packages.

An exampe using threeparttable:

\documentclass[12pt,notitlepage]{article}%
\usepackage{lipsum}
\usepackage{threeparttable}

\begin{document}

\section{A}
\lipsum[4-6]
\section{B}
\begin{table}
\centering
\begin{threeparttable}
\caption{Summary table for non-tangential per and post flyby the moon}
\label{tab:part_3_1_summary}
\begin{tabular}{|l|l|l|}\hline
semimajor axis $a$       & 300000  & 262413    \\ \hline
true anamoly $f$         & 163.76   & 176.08   \\\hline
$r_p$                    & 6678 & 1689\tnote{1} \\ \hline
\end{tabular}
\begin{tablenotes}
\item[1] spacecraft will hit earth on way back since $r_p<r_{earth}$
\end{tablenotes}
\end{threeparttable}
\end{table}
\section{C}
\lipsum[4-10]

\end{document}

enter image description here

And the same table using ctable:

\documentclass[12pt,notitlepage]{article}%
\usepackage{lipsum}
\usepackage{ctable}

\begin{document}

\section{A}
\lipsum[4-6]
\section{B}
\ctable[
caption = Summary table for non-tangential per and post flyby the moon.
label={tab:part_3_1_summary}
]{|l|l|l|}
{\tnote[1]{spacecraft will hit earth on way back since $r_p<r_{earth}$}}
{
\hline
semimajor axis $a$       & 300000  & 262413  \\ \hline
true anamoly $f$         & 163.76   & 176.08   \\ \hline
$r_p$ & 6678 & 1689 \\ 
\hline
}
\section{C}
\lipsum[4-10]

\end{document}

enter image description here

Both packages offer some customization possibilities for the note formatting; please refer to the documentation of the packages


I followed the advice in Gonzalo Medina's answer using threeparttable, but I had some trouble centering the caption above my table correctly. It was anchored to the left edge of the table, but because the caption was quite long, it extended beyond the left edge of the table.

My solution was to move \begin{threeparttable} below the caption, before the tabular environment. This way, the caption is centered within the float and uses its full width (which may or may not be what you want). The footnote is beneath the table and extends only the full width of the table, as expected.

\documentclass[12pt,notitlepage]{article}%
\usepackage{threeparttable}

\begin{document}

\begin{table}
\centering
\caption{Here's my long caption text that I want centered on the page.
\label{tab:simulation_parameters}}
\begin{threeparttable}
\begin{tabular}{lp{1.7in}}
\hline
Material & Index of refraction\\ 
\hline
silicon & 3.47772\\
silicon dioxide & 1.54\\
silicon nitride & 2.217\\
HSQ\tnote{a} & 1.39\\ \hline
\end{tabular}
\begin{tablenotes}
\item[a] Here's my footnote.
\end{tablenotes}
\end{threeparttable}
\end{table}

\end{document}

enter image description here