Interlayer coupling in commensurate and incommensurate bilayer structures of transition-metal dichalcogenides