Normally, Lead assignment rules are triggered upon new lead, and, from the API (i.e. Marketo), Marketo must supply an AssignmentRuleHeader.
If you want to reassign leads based on an update, then, as you know, in the UI, the user must manually tick the checkbox to apply assignment rules. The same holds true for any API client, the AssignmentRuleHeader would ...
There are two problem with your code:
When you make call to Marketo Rest API, it results application/json;charset=UTF-8 Content-Type header in response instead of application/json. That's the reason it is failing system assertion test, So I have corrected that line in your code
System.assert(contentType == 'application/json;charset=UTF-8');
Endpoint URL ...
To prevent duplicates, Marketo assumes leads with the same email address are the same person. New leads with known emails are automatically merged with their matching lead in Marketo (this feature can be disabled by contacting Marketo support, which was necessary in our case).
More advanced duplicate prevention is available through a variety of tools. ...
You can handle in Salesforce through Workflow Rule where
Evaluation Criteria: Evaluate the rule when a record is created, and any time it's edited to subsequently meet criteria
Rule Criteria: Phone Number is not null.
Workflow Action: Field Update Details
Based on formula like this:
If there are some leads for which rules are working fine, you should dig deeper to find the differences between those and for which the rules aren't working. You should check the following
1) The lead owner is being set correctly in all cases
2) I would presume you already have the syncing turned on (since rules are working for some) using Login --> ...