The short answer is you can't.
The long answer:
If you take a look at the Google Apps Script documentation for custom functions, you will see a list of all the functions that you can do.
The problem is you can only set the value, not the color of the cell. You will get a permission denied.
To show you this, look at the following script:
function colorChanger(text, cellref, colorref) {
var sheet = SpreadsheetApp.getActiveSpreadsheet();
var color = sheet.getRange(colorref).getBackground();
var cell = sheet.getRange(cellref);
cell.setBackground(color);
return text;
}
By theory, it should work, however the scripting doesn't support it.
When running in google-sheets you get the following:

According to their documentation they say this:
If your custom function throws the error message You do not have
permission to call X service., the service requires user authorization
and thus cannot be used in a custom function.
Reference: https://developers.google.com/apps-script/guides/sheets/functions