If you use a NAS server for your time machine backups then you could potentially use a filesystem on that server that supports periodic readonly snapshots. This would ensure that previous backups aren't encrypted by ransomware. FreeNAS with ZFS is probably the easiest way to set this up, though you could also accomplish the same thing on any OS that supported ZFS.
To be honest, even with FreeNAS UI, this isn't the easiest. Administrating ZFS is not straightforward and you would definitely need to read up on ZFS Snapshots. Additionally, it's expensive, as now you need a server for backups as opposed to just an external disk.
There is potentially a much better solution coming soon. Apple's new filesystem, APFS, has already rolled out to iOS 10.3. I can't find confirmation that it will be in macOS 10.13, but I am imagine it's right around the corner.
APFS supports snapshotting natively, and if Apple does this right, Time Machine backups should use readonly snapshots that should hopefully be ransomware proof. We will have to wait and see what happens though.