It happened at Cockett Police Station in Swansea.
Det Insp Ricky Price was given a written final warning for gross misconduct following a misconduct hearing held earlier this week.
The head of professional standards for the force said a final written warning was “an extremely serious outcome”.
Police confirmed that Mr Price, who had completed 22 years with the force, offered his resignation but withdrew it before the misconduct hearing began.
It is understood Det Insp Price is being moved to a different job with South Wales Police and will receive “special training” for his behaviour.
Ch Supt Dorian Lloyd, for South Wales Police, said: “The sanction of a Final Written Warning is an extremely serious outcome and will remain on the officer’s personal record for the next 18 months.
“South Wales Police employs almost 5,000 police officers and members of staff, who demonstrate the very highest levels of professional conduct and integrity at all times.
“Members of the public and the communities of South Wales should be reassured that the force’s Professional Standards Department takes any complaint or allegation relating to an individual’s conduct extremely seriously, as has been demonstrated here.
“We will always ensure that such matters are thoroughly investigated and that appropriate action is taken.”