In a purely communist society, a private detective is not possible, because private transactions don't take place. All production, including the production of detective services, would be carried out by the state and all consumption, including of the consumption of detective services, would be allocated by the state. That still leaves plenty of options, including:
- Set the story in an impure communist society, in which much production (e.g. industrial production) is carried out by the state, but not all, and much consumption is allocated by the state (maybe the consumption of essentials or non-discretionary goods and services). This would still leave room for private transactions for services such as detectives.
- Set the story in a pure communist society and have the detective operating on the black market.
- Set the story in a pure communist society and have the detective services provided by the state. They could be a "private" detective in the sense they investigate in response to the request of an individual, even though they're paid by the state. In that case they may not have the same social role or rights and privileges as police.
- Have some quirky, specific reason why a society might allocate everything according to communist principles, except detective services which are private.
The choice would really depend on the needs of the story. If it's a story about bureaucracy, option 3 could give lots of fun juxtapositions with the tough, hard-boiled detective filling out lots of necessary paperwork. On the other hand, if it's a story about cynicism and exposing the underbelly of society, then a black market private detective might work.