In order to split a long label without spaces, you can use the \seqsplit
command from the seqsplit package. The following is an adaption of David's answer and also shows the necessity of wrapping long labels:
\documentclass{article}
\usepackage[%showframe, % show helper lines
paperwidth=10cm, paperheight=7cm,
hmargin=24mm,vmargin=4mm, marginparwidth=17mm,
]{geometry}
\usepackage{seqsplit}
\usepackage{showkeys}
\usepackage{xstring}
\renewcommand*\showkeyslabelformat[1]{%
\noexpandarg%
% instead of \textvisiblespace you can also put in ~
% if you want to keep a plain space at space characters
\StrSubstitute{\(\{\)#1\(\}\)}{ }{\textvisiblespace}[\TEMP]%
\parbox[t]{\marginparwidth}{\raggedright\normalfont\small\ttfamily\expandafter\seqsplit\expandafter{\TEMP}}}
\begin{document}
\begin{equation}
(a\cdot b ) \cdot c = a\cdot (b\cdot c)
\label{eq:groupassociativity}
\end{equation}
\begin{figure}[ht]
\centering
\rule{1cm}{1cm}
\caption{default}
\label{fig:a very very very long and detailed label}
\end{figure}
\end{document}

For the spaces, one needs to replace the spaces within the seqsplit, either by ~
for keeping a space or by something else like \textvisiblespace
to visualize it better.