This question isn't really about removing spaces at the end of a line, but about removing them at the end of a paragraph.
All skips at the end of a line are already ignored automatically.
A possible solution would be to define \customhspace as follows:
\newcommand*\customhspace[1]{\unskip\hspace{#1}\ignorespaces}
This doesn't quite behave like an ordinary \hspace in the middle of a line, however, since it removes a space preceding or following it (which includes ordinary spaces).
Whether this is an advantage or a disadvantage depends on how you intend to use this macro.
Demonstration:
Here is a little sample document that demonstrates how this works.
Note that it matters whether an \hspace{...} is surrounded by spaces, while it does not for \customhspace.
\documentclass{article}
\newcommand*\customhspace[1]{\unskip\hspace{#1}\ignorespaces}
\begin{document}
AAA \hspace{2em} BBB
AAA \hspace{2em}BBB
AAA\hspace{2em} BBB
AAA\hspace{2em}BBB
AAA \customhspace{2em} BBB
\hfill AAA \hspace{2em}
\hfill AAA\hspace{2em}% % <- see explanation below
\hfill AAA\customhspace{2em}
\hfill AAA
\end{document}

Explanation:
TeX removes the last item in a paragraph if it is glue (a skip/space), but only one piece of glue will be removed in this way.
This means that if you have multiple consecutive spaces at the end of a paragraph, all but the last one will still be there.
A paragraph produced by \hfill AAA \hspace{2pt}, followed by a newline, actually ends with three pieces of glue:
- The explicit space character preceding
\hspace.
- The
\hspace{2pt} itself
- The newline also produces a space.
If you remove the preceding space and comment out the newline (see What is the use of percent signs (%) at the end of lines?), \hspace{2pt} will be the last item in the paragraph and will be removed.
The following paragraph will not have a space at the end:
\hfill AAA\hspace{2pt}%
You don't want to do this every time, of course.
In the definition for \customhspace above, I instead included an \ignorespaces to make TeX ignore skips directly following this command, and \unskip to remove the preceding space, if there is one.
\newcommand*\customhspace[1]{\unskip\hskip #1\ignorespaces}? That wayAAA \customhspace{2pt} BBBwon't be exactly the same asAAA \hspace{2pt} BBBthough, since the additional ordinary spaces before/after the\hspaceare removed. – Circumscribe Aug 30 '18 at 08:07\hspace{#1}instead of\hskip #1.) – Circumscribe Aug 30 '18 at 08:13\ignorespaces. Don't hesitate to post an answer. I will review your idea in 4/5 hours. – Colas Aug 30 '18 at 09:53