Rambam points out in Hilchos Ishus 1:4 that at that time it was permitted.
Before the Torah was given, when a man would meet a woman in the
marketplace, and he and she desired, he could give her payment, engage
in relations with her wherever they desired, and then depart. Such a
woman is referred to as a harlot.3
3. The Ra'avad and others differ and maintain that a woman
is not considered to be a harlot unless she is a professional
prostitute. The difference between this approach and the Rambam's
involves only the severity of the prohibition. Both agree that sexual
relations outside the context of marriage are forbidden. With regard
to a pilegesh, a woman one designates as a sexual partner but who is
not consecrated as a wife, see Hilchot Melachim 4:4.
In this case therefore, Yehudah needed to find a woman whose profession was that of קְדֵשָה as only such a woman was permitted at that time. As the Art Scroll commentary introduction to Vayeishev 38:14-23 explains:
Judah's action must be viewed in the perspective of the time in which
he lived. As Rambam (Hil. Ishus
writes, harlotry was permitted in those times - just as non-kosher
foods were not forbidden - before the Torah was given. Even though the
Patriarchs - and presumably their families - observed the Torah before
it was given, they did so voluntarily, so that it was conceivable
that where necessary they would act according to the laws that were
obligatory at that time. Consequently if the Divine Plan required
Judah to cohabit with a "harlot"he would be permitted to do so. [Cf.
the case of Jacob marrying two sisters which later Torah law would
Thus, once Yehudah attempted to find consolation in the arms of a woman, he could only do so by either marrying (which he felt was not yet proper) of hiring a professional woman. Anything else was forbidden to Bnai Noach at that time.