We study the influence of strong spin-orbit interaction on the formation of flat bands in relaxed twisted bilayer WSe$_2$. Flat bands, well separated in energy, emerge at the band edges for twist angles θ near 0° and 60°. For θ near 0°, the interlayer hybridization together with a moiré potential determines the electronic structure. The bands near the valence band edge have nontrivial topology, with Chern numbers equal to +1 or -1. We propose that the nontrivial topology of the first band can be probed experimentally for twist angles less than a critical angle of 3.5°. For θ near 60°, the flattening of the bands arising from the K point of the unit cell Brillouin zone is a result of atomic rearrangements in the individual layers. Our findings on the flat bands and the localization of their wave functions for both ranges of θ match well with recent experimental observations.