Sweeney spent three seasons with the Stags playing 127 games, scoring seven goals, and also had spells captaining the side.
“I am delighted to have signed for Dundee and can’t wait to get going and looking forward to the new challenge,” he said.
Sweeney began his career with AFC Wimbledon and broke into the first team before transfer to Stoke City in 2016.
Injury headaches for Hucknall boss ahead of trip to Bourne
Joe Worrall has goosebumps thinking about Nottingham Forest's Premier League home return against West Ham United
Who can you spot in these great retro photos from Hucknall's youth football scene?
Crunch game looming in title race for Papplewick & Linby
Former Mansfield Town boss Mick Jones dies aged 75
While under contract at Stoke, he spent two loan spells at Bristol Rovers before a season on loan at Mansfield and a permanent move to them in 2019.
Sweeney also has nine caps for Republic of Ireland Under 21s.