This is still so absurd. Sonny and Ava have joint custody. He cannot just keep Avery from her with the ease that he has. Why Ric hasn't petitioned the court to have Sonny forced to comply is beyond me.
On November 10, 2015, Ava was awarded sole custody of Avery after goading Sonny into threatening her (she recorded it) and Sonny was given visitation rights.
During The Nurses' Ball 2016, after months of trying to find something on Ava, Carly finds a sex tape of her and then-D.A. Paul Hornsby and tries to use against Ava to get Avery back but Ava isn't fazed until Carly lets Paul know that she has it.
When Paul finds out he threatens to turn Ava into the police for killing Connie Falconeri (he has the recording). Ava finally relents and basically gives custody over to Sonny with an agreement that she can still see Avery.
As of July 14, 2017, Sonny has full physical and legal custody of Avery and Ava has no right to her anymore. It was also revealed that they had come to an agreement privately. That stayed until May 2018, where Ava blackmailed Sonny into giving her joint custody. Sonny and Ava have continually fought over custody of Avery since she was born.