The way I read it, the imprisonment does not have to have been either for sexual offences or the offence of rape.
Section 66
Placement in preventive detention
(1) The court orders preventive detention in addition to a sentence of imprisonment where
1. a person has been sentenced for an intentional offence to imprisonment for a term of at least two years and
a) the offence was directed against life, physical integrity, personal liberty or sexual self-determination,
b) the offence falls under Division 1, 7, 20 or 28 of the Special Part or under the Code of Crimes against International Law (
Völkerstrafgesetzbuch) or the Narcotics Act (
Betäubungsmittelgesetz) and the maximum possible sentence is imprisonment for a term of at least 10 years or
c) the conditions of section 145a are met insofar as an order was made for the supervision of conduct on the basis of an offence under letter (a) or (b), or if the conditions of section 323a are met insofar as the offence committed in a state of intoxication was one of those referred to in letter (a) or (b),
...
4. an overall evaluation of the offender and the offences committed leads to the conclusion that, on account of the propensity to commit serious crimes, in particular of a type which results in severe emotional trauma or physical injury to the victim, the offender poses a danger to the general public at the time of the conviction.