Grottaglie, il castello conteso