A gunman has killed four hostages in south-west Germany before shooting himself while resisting eviction from his apartment building.