I don't have an answer on what is going wrong with the Automapper configuration. However, your question is How can I avoid this? and How should I be doing this so I want to answer with some advice: don't put business logic in your mapper configuration.
The reason not to do it are:
- Mapping objects should be kept as simple as possible, don't add magic like this as it makes the code hard to understand/follow.
- Your code is harder to test