it is written in book that while calculating density, z=1 for ionic compounds such as CsCl forming BCC structures.but in bcc structures no of atoms =2 then why have we taken Z=1
You yourself answered the question correctly. In case of ionic compounds, we consider the number of formula units per unit cell. Thus, Z will denote the number of formula units per unit cell and not the number of individual ions. Since CsCl has BCC structure, therefore Z = 1.
Another important point to note is that for ionic compounds, we use the term formula units and not molecules. Molecules are formed by sharing of atoms and not by transfer of electrons.