MATL, 19 bytes
,!ix"0GYs@12XQ!g]v! Inputs are M (matrix), H (column vector), V (column vector). The row separator is ;.
Try it online! Or verify all test cases: 1, 2, 3, 4, 5.
Explanation
I'll add an explanation tomorrow later. This does the cumulative sum horizontally, then vertically.
, % Do the following twice ! % First time this inputs M implicitly. Transpose. Second time % it transposes the result of the horizontal cumulative sum ix % Input H (first time) or V (second time). Delete it; but gets % copied into clipboard G " % For each column of the matrix 0G % Push most recent input: H (first time) or V (second) Ys % Cumulative sum. This produces a vector of integer values % such that all columns (first time) or rows (second) of M % with the same value in this vector should be cumulatively % summed @ % Push current column of M transposed (first time) or M after % horizontal cumulative sum (second time) 12XQ % Cumulative sum. Gives a cell array of row vectors !g % Join those vectors into one row vector ] % End v % Concatenate the row vectors vertically into a matrix ! % Transpose. This corrects for the fact that each column vector % of the matrix was cumulatively summed into a row vector % Implicit end. Implicit display