If someone masturbates whilst fasting, the fast will break. Qadhā will be Wājib, not Kaffārah. Kaffārah not being Fardh is because deriving sexual pleasure is only complete when two parties are involved, so the effect is also lessened when no one else is involved.
اذا عالج ذكره بيده حتى أمنى…عامة مشائخنا
استحسنو وأفتوا بالفساد. وفى الخلاصة:لا كفارة عليه
تاتارخانية ص 0 / 2 الهندية ص 205 / 1 فتح القدير ونهاية ص 234 / 2 احكام ص 290
The act in itself is Makrūh Taḥrīmī (prohibitively disliked) according to Hanafī research, as Allāmah ibn Humām R.A has stated in Fathul Qadeer. Imām Mālik R.A is of the opinion that it’s Harām. Faqeeh Abul Layth Samarqandī R.A, who is a Hanafī, also classed it as Harām.
Extracted from A Gift for Ramadhan, Page 63.