Can I write in my SOP that I want to join labs which aren't belonged to the department I apply? I want to work on a research which requires both field A and field B. On the school I want to pursue, both lab X and X' from department A work on A+B. If possible, I'd like to work in both lab because there is some niches in both lab X and X' will be needed on my proposed research. 

However, I would like to apply to department B because I don't want to limit myself inside a field. I want to broaden my knowledge as much as I can, before concentrating on my thesis. I don't think that this approach is bad.

Being said that, is there anything that I should be aware of when writing the SOP to department B? Would mention about the labs which aren't belonged to the department harm me in some ways? Or should I just apply to department A? Is there any harm if in my SOP there is a paragraph saying that I want to learn more about B (than A)?
This entirely depends on the university culture. Some universities and labs are very free in terms of the flow of faculty and students, others are much more siloed. It's impossible for us to give you a general answer. 

You should instead talk to students and postdocs enrolled at that university and in those labs and ask them whether it's possible. They are the ones who are most likely able to tell you what the situation is there.