Here is a possibility using a command called \mySpecialCommas
to make commas active in math mode only when said command is used. When \mySpecialCommas
is used inside a math formula, a line break after a comma is allowed if, and only if the comma is followed by a space token (which can be obtained from the end-of-line, as usual). So, make sure commas inside your tuples are not followed by a space. Beware of the final comma in your example, unless you are fine with the closing brace appearing at the beginning of a line. This should work with any engine.
\documentclass{article}
\usepackage{lipsum}
\makeatletter
\newcommand*{\my@specialComma}{%
\futurelet\next\my@specialComma@next
}
\newcommand*{\my@specialComma@next}{%
\mathchar "613B % the normal mathematical comma
\ifx\next\@sptoken
\penalty 0 % higher values make a line break less desirable
\mskip 0mu plus 2mu\relax % add stretchability for better line breaks
\fi
}
{\catcode`\,=\active
\gdef,{\my@specialComma}%
}
\newcommand*{\mySpecialCommas}{\mathcode`\,="8000 } %space intended
\makeatother
\begin{document}
\lipsum*[1][1-3]
This is a long equation: $\mySpecialCommas
A = \{ (1,2), (1,3), (1,5), (2,1), (2,2), (2,3), (1,2), (1,3), (1,5), (2,1),
(2,2), (2,3),(1,2), (1,3), (1,5), (2,1), (2,2), (2,3),(1,2), (1,3), (1,5),
(2,1), (2,2), (2,3),(1,2), (1,3), (1,5), (2,1), (2,2), (2,3) \}$.
\medskip
This is a long equation: $\mySpecialCommas
A = \{ (1,2), (1,3), (1,5), (2,1), (2,2), (2,3), (1,2), (1,3), (1,5), (2,1),
(2,2), (2,3),(1,2), (1,3), (1,5), (2,1), (2,2), (2,3),(1,2), (1,3), (1,5),
(2,1), (2,2), (2,3),(1,2), (1,3), (1,5), (2,1), (2,2), (2,3),\}$.
\medskip
Normal text can have commas, no problem.
\end{document}

\penalty 0
or someting like that.(1,2)
. Instead you need to help TeX by telling it which commas are good to break at. This is done via adding\allowbreak
after the relevant commas.