This is an unattributed athar that its authenticity is undetermined.
The quote you provided is from an unattributed athar in the footnotes of Ihyā' 'Ulūm ad-Dīn (The Revival of Religious Sciences), Vol. 2, pp. 45 by Al-Ghazali:
وقد زبر عمر رضي الله عنه امرأته لما راجعته وقال ما أنت إلا لعبة في جانب البيت إن كانت لنا إليك حاجة وإلا جلست كما أنت فإذن فيهن شر وفيهن ضعف فالسياسة والخشونة علاج الشر والمطايبة والرحمة علاج الضعف فالطبيب الحاذق هو الذي يقدر العلاج بقدر الداء فلينظر الرجل أولاإلى أخلاقها بالتجربة ثم ليعاملها بما يصلحها كما يقتضيه حَالُهَا
— NOTE: Translation by Madelain Farah:
'Umar scolded his wife when she talked back to him saying, "You are no more than a toy in a corner of the house; if we have need of you [we take you], otherwise, you sit as you are." Thus there is evil and weakness in them [women]; while diplomacy and harshness are a cure for evil, consolation and mercy are the cure for weakness. The skillful doctor is one who can estimate the amount of cure needed for the ailment; so let the man first know her character through experience, then let him deal with her in a manner that will set her straight in accordance with her state.
Al-Ghazali did not attribute this athar. However, this particular quote comes from a book called Ibtilā' al-Akhyār bi al-Nissā' al-Ashrār (Arabic: إبتلاء الأخيار بالنساء الأشرار), which means the tests or tribulations of the good by evil women. This poetry book was authored by Ismā'īl ibn Nasr ibn 'Abdul-Mohsin as-Salāhi (Arabic: اسماعيل بن نصر بن عبد المحسن السلاحي المعروف) in which he writes about how good people (e.g., Prophet Nūh and Prophet Lūt) were tested with evil women. Not much is known about the author of the book. The quote comes from his gloss about one of his verses, but again without attribution.