Density‐dependent dispersal (DDD) has been observed across taxa, and is expected to affect phenomena such as population dynamics, biological invasions, range expansions, and community assembly. However, little is known about whether the patterns of DDD are robust to changes in the environment. For example, the pre‐dispersal context could affect the physiology of organisms, which in turn could alter their DDD. Similarly, in sexually reproducing organisms, males and females might be differentially affected by the environment, with possible changes in their dispersal properties. To investigate some of these issues, we performed three independent experiments using laboratory populations of Drosophila melanogaster, which tested the effects of pre‐dispersal context, sex of the dispersers and presence of mates on DDD. A two‐patch dispersal setup was used to estimate the dispersal propensity and temporal dispersal profile of adult fruit flies. Comparing the data from two different pre‐dispersal contexts (variable and uniform pre‐dispersal adult densities), we found that longer pre‐dispersal exposure to higher densities led to stronger negative DDD in both males and females. Surprisingly, this change in DDD strength was accompanied by a switch in the direction of sex‐biased dispersal: from female‐biased dispersal at a low density to male‐biased dispersal at a high density. Moreover, we found that patterns of both density dependence and sex bias were contingent upon the interaction of males and females, as neither sex exhibited DDD in the absence of the other. Taken together, these results suggest that DDD and sex‐biased dispersal can be labile and be driven by the environmental context. Finally, we discuss the potential implications of these findings in terms of various ecological and evolutionary processes.